mirror of
https://github.com/tenrok/axios.git
synced 2026-06-08 17:22:34 +03:00
fix: status is missing in AxiosError on and after v1.13.3 (#7368)
* test: add error handling tests for fetch and http adapters with status code * fix: improve error handling in fetch adapter by including request and response in AxiosError * fix: skip fetch test if fetch is not supported * Update lib/adapters/fetch.js Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * fix: improve error handling in fetch adapter by using the correct request object --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -40,4 +40,56 @@ describe('issues', function () {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('7364', function () {
|
||||
it('fetch: should have status code in axios error', async function () {
|
||||
const isFetchSupported = typeof fetch === 'function';
|
||||
if (!isFetchSupported) {
|
||||
this.skip();
|
||||
}
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
res.statusCode = 400;
|
||||
res.end();
|
||||
}).listen(0);
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL: `http://localhost:${server.address().port}`,
|
||||
adapter: "fetch",
|
||||
});
|
||||
|
||||
try {
|
||||
await instance.get("/status/400");
|
||||
} catch (error) {
|
||||
assert.equal(error.name, "AxiosError");
|
||||
assert.equal(error.isAxiosError, true);
|
||||
assert.equal(error.status, 400);
|
||||
} finally {
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('http: should have status code in axios error', async function () {
|
||||
const server = http.createServer((req, res) => {
|
||||
res.statusCode = 400;
|
||||
res.end();
|
||||
}).listen(0);
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL: `http://localhost:${server.address().port}`,
|
||||
adapter: "http",
|
||||
});
|
||||
|
||||
try {
|
||||
await instance.get("/status/400");
|
||||
} catch (error) {
|
||||
assert.equal(error.name, "AxiosError");
|
||||
assert.equal(error.isAxiosError, true);
|
||||
assert.equal(error.status, 400);
|
||||
} finally {
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user