Skip to content

Commit

Permalink
Move network error detection into a separate package
Browse files Browse the repository at this point in the history
Fixes #74
  • Loading branch information
sindresorhus committed Sep 26, 2023
1 parent 79c5fc7 commit ba073f3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
13 changes: 2 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import retry from 'retry';

const networkErrorMsgs = new Set([
'Failed to fetch', // Chrome
'NetworkError when attempting to fetch resource.', // Firefox
'The Internet connection appears to be offline.', // Safari
'Network request failed', // `cross-fetch`
'fetch failed', // Undici (Node.js)
]);
import isNetworkError from 'is-network-error';

export class AbortError extends Error {
constructor(message) {
Expand Down Expand Up @@ -34,8 +27,6 @@ const decorateErrorWithCounts = (error, attemptNumber, options) => {
return error;
};

const isNetworkError = errorMessage => networkErrorMsgs.has(errorMessage);

export default async function pRetry(input, options) {
return new Promise((resolve, reject) => {
options = {
Expand Down Expand Up @@ -75,7 +66,7 @@ export default async function pRetry(input, options) {
throw error.originalError;
}

if (error instanceof TypeError && !isNetworkError(error.message)) {
if (error instanceof TypeError && !isNetworkError(error)) {
throw error;
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
],
"dependencies": {
"@types/retry": "0.12.2",
"is-network-error": "^1.0.0",
"retry": "^0.13.1"
},
"devDependencies": {
Expand Down

0 comments on commit ba073f3

Please sign in to comment.