Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set request object on axios errors #264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ function createAxiosError(message, config, response, code) {
var error = new Error(message);
error.isAxiosError = true;
error.config = config;
error.request = {
responseUrl: config.url,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be responseURL and not responseUrl. I least in my browser URL is uppercased. (see #287)

};
if (response !== undefined) {
error.response = response;
}
Expand Down
1 change: 1 addition & 0 deletions test/abort_request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("requestAborted spec", function () {
expect(error.code).to.equal("ECONNABORTED");
expect(error.message).to.equal("Request aborted");
expect(error.isAxiosError).to.be.true;
expect(error.request.responseUrl).to.equal("/foo");
}
);
});
Expand Down
13 changes: 13 additions & 0 deletions test/basics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,17 @@ describe("MockAdapter basics", function () {
expect(error.isAxiosError).to.be.true;
});
});

it("sets the original request url in the response.request.responseUrl property on errors", function () {
mock.onGet("/foo").reply(404);

return instance
.get("/foo")
.then(function () {
expect(true).to.be.false;
})
.catch(function (error) {
expect(error.request.responseUrl).to.equal("/foo");
});
});
});
1 change: 1 addition & 0 deletions test/network_error.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("networkError spec", function () {
expect(error.response).to.not.exist;
expect(error.message).to.equal("Network Error");
expect(error.isAxiosError).to.be.true;
expect(error.request.responseUrl).to.equal("/foo");
}
);
});
Expand Down
2 changes: 2 additions & 0 deletions test/timeout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("timeout spec", function () {
expect(error.code).to.equal("ECONNABORTED");
expect(error.message).to.equal("timeout of 0ms exceeded");
expect(error.isAxiosError).to.be.true;
expect(error.request.responseUrl).to.equal("/foo");
}
);
});
Expand Down Expand Up @@ -61,6 +62,7 @@ describe("timeout spec", function () {
expect(error.code).to.equal("ECONNABORTED");
expect(error.message).to.equal(timeoutErrorMessage);
expect(error.isAxiosError).to.be.true;
expect(error.request.responseUrl).to.equal("/foo");
}
);
});
Expand Down