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

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

Merged
merged 46 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3f2f496
chore(ci): Add release-it script;
DigitalBrainJS Dec 10, 2022
1bfc41b
Merge branch 'chore/release-it' into v1.x
DigitalBrainJS Dec 10, 2022
acaf0f4
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 15, 2022
8a5de86
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 15, 2022
cff9271
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 17, 2022
67afe20
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 19, 2022
dc7b66d
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 22, 2022
716eb59
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 23, 2022
10216bf
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 29, 2022
3b199f4
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 7, 2023
f3d444f
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 19, 2023
077c381
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 26, 2023
f598657
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 31, 2023
7bf5713
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Feb 5, 2023
81a8bd6
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Mar 8, 2023
f8bb158
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 5, 2023
3f1c768
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 18, 2023
a9b0418
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 25, 2023
1a16f4e
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 27, 2023
5e22e2f
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS May 10, 2023
b7c77b0
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 25, 2023
2200038
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 25, 2023
df38e0c
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 26, 2023
878548a
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 26, 2023
7a33bcd
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Aug 28, 2023
5cafdeb
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Sep 13, 2023
f0e6b28
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Sep 26, 2023
98371b0
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Sep 28, 2023
bee6e45
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Oct 4, 2023
c97df04
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Oct 26, 2023
62274b7
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Oct 28, 2023
2496392
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Nov 15, 2023
127f629
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 2, 2024
435bbfa
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 25, 2024
72c888c
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 21, 2024
1e5552a
feat(adapter): add fetch adapter;
DigitalBrainJS Apr 27, 2024
c0392c9
fix(test): skip fetch tests if global `fetch` function is not available;
DigitalBrainJS Apr 27, 2024
4ba5f01
fix(CI): disable fail-fast option;
DigitalBrainJS Apr 27, 2024
fe0a2ca
fix(CI): add v21 to matrix tests;
DigitalBrainJS Apr 27, 2024
30f66fd
fix(fetch): wrap buffer to an Uint8Array to avoid detached Buffer err…
DigitalBrainJS Apr 28, 2024
f4b9f16
fix(fetch): remove the Blob-based Content-Type header setting to matc…
DigitalBrainJS Apr 28, 2024
d01386e
feat(progress): add throttle for progress events;
DigitalBrainJS Apr 28, 2024
565c7d9
Merge branch 'v1.x' of https://github.com/axios/axios into feat/axios…
DigitalBrainJS Apr 28, 2024
b21be21
fix(fetch): fix cases when ReadableStream or Response.body are not av…
DigitalBrainJS May 2, 2024
fd69f9f
refactor(fetch): treat `TypeError: fetch failed` as an AxiosError.ERR…
DigitalBrainJS May 3, 2024
f0c8da2
Merge branch 'v1.x' into feat/axios-fetch-adapter
DigitalBrainJS May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/adapters/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
10 changes: 10 additions & 0 deletions test/unit/adapters/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,14 @@ describe('supports fetch with nodejs', function () {

assert.strictEqual(data, '/?test=1&foo=1&bar=2');
});

it('should handle fetch failed error as an AxiosError with ERR_NETWORK code', async () => {
try{
await fetchAxios('http://notExistsUrl.in.nowhere');
assert.fail('should fail');
} catch (err) {
assert.strictEqual(String(err), 'AxiosError: Network Error');
assert.strictEqual(err.cause && err.cause.code, 'ENOTFOUND');
}
});
});