Skip to content

Commit ba073f3

Browse files
committedSep 26, 2023
Move network error detection into a separate package
Fixes #74
1 parent 79c5fc7 commit ba073f3

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed
 

‎index.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import retry from 'retry';
2-
3-
const networkErrorMsgs = new Set([
4-
'Failed to fetch', // Chrome
5-
'NetworkError when attempting to fetch resource.', // Firefox
6-
'The Internet connection appears to be offline.', // Safari
7-
'Network request failed', // `cross-fetch`
8-
'fetch failed', // Undici (Node.js)
9-
]);
2+
import isNetworkError from 'is-network-error';
103

114
export class AbortError extends Error {
125
constructor(message) {
@@ -34,8 +27,6 @@ const decorateErrorWithCounts = (error, attemptNumber, options) => {
3427
return error;
3528
};
3629

37-
const isNetworkError = errorMessage => networkErrorMsgs.has(errorMessage);
38-
3930
export default async function pRetry(input, options) {
4031
return new Promise((resolve, reject) => {
4132
options = {
@@ -75,7 +66,7 @@ export default async function pRetry(input, options) {
7566
throw error.originalError;
7667
}
7768

78-
if (error instanceof TypeError && !isNetworkError(error.message)) {
69+
if (error instanceof TypeError && !isNetworkError(error)) {
7970
throw error;
8071
}
8172

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
],
4444
"dependencies": {
4545
"@types/retry": "0.12.2",
46+
"is-network-error": "^1.0.0",
4647
"retry": "^0.13.1"
4748
},
4849
"devDependencies": {

0 commit comments

Comments
 (0)
Please sign in to comment.