2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-14 18:42:33 +03:00

fix(fetch): treat fetch-related TypeError as an AxiosError.ERR_NETWORK error; (#6380)

This commit is contained in:
Dmitriy Mozgovoy
2024-05-07 21:26:46 +03:00
committed by GitHub
parent 81e0455b7b
commit bb5f9a5ab7
2 changed files with 18 additions and 5 deletions
+8 -5
View File
@@ -196,13 +196,16 @@ export default isFetchSupported && (async (config) => {
} catch (err) {
onFinish();
let {code} = err;
if (err.name === 'NetworkError') {
code = AxiosError.ERR_NETWORK;
if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
throw Object.assign(
new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
{
cause: err.cause || err
}
)
}
throw AxiosError.from(err, code, config, request);
throw AxiosError.from(err, err && err.code, config, request);
}
});