Comparing version 4.3.0 to 4.4.0
@@ -55,4 +55,4 @@ import {OperationOptions} from 'retry'; | ||
It doesn't retry on `TypeError` as that's a user error. The only exclusion to this logic is when `TypeError` is thrown by `fetch`'s API with the message 'Failed to fetch', [which indicates that a request was not successful due to a network error](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful). | ||
However, beware that `fetch` may throw `TypeError` with different error messages on different platforms for similar situations. See [whatwg/fetch#526 (comment)](https://github.com/whatwg/fetch/issues/526#issuecomment-554604080)." | ||
Does not retry on most `TypeErrors`, with the exception of network errors. This is done on a best case basis as different browsers have different [messages](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful) to indicate this. | ||
See [whatwg/fetch#526 (comment)](https://github.com/whatwg/fetch/issues/526#issuecomment-554604080) | ||
@@ -59,0 +59,0 @@ @param input - Receives the number of attempts as the first argument and is expected to return a `Promise` or any value. |
10
index.js
'use strict'; | ||
const retry = require('retry'); | ||
const networkErrorMsgs = [ | ||
'Failed to fetch', // Chrome | ||
'NetworkError when attempting to fetch resource', // Firefox | ||
'The Internet connection appears to be offline' // Safari | ||
]; | ||
class AbortError extends Error { | ||
@@ -30,2 +36,4 @@ constructor(message) { | ||
const isNetworkError = errorMessage => networkErrorMsgs.includes(errorMessage); | ||
const pRetry = (input, options) => new Promise((resolve, reject) => { | ||
@@ -52,3 +60,3 @@ options = { | ||
reject(error.originalError); | ||
} else if (error instanceof TypeError && error.message !== 'Failed to fetch') { | ||
} else if (error instanceof TypeError && !isNetworkError(error.message)) { | ||
operation.stop(); | ||
@@ -55,0 +63,0 @@ reject(error); |
{ | ||
"name": "p-retry", | ||
"version": "4.3.0", | ||
"version": "4.4.0", | ||
"description": "Retry a promise-returning or async function", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -42,4 +42,5 @@ # p-retry | ||
It doesn't retry on `TypeError` as that's a user error. The only exclusion to this logic is when `TypeError` is thrown by `fetch`'s API with the message 'Failed to fetch', [which indicates that a request was not successful due to a network error](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful). However, beware that `fetch` may throw `TypeError` with different error messages on different platforms for similar situations. See [whatwg/fetch#526 (comment)](https://github.com/whatwg/fetch/issues/526#issuecomment-554604080)." | ||
Does not retry on most `TypeErrors`, with the exception of network errors. This is done on a best case basis as different browsers have different [messages](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful) to indicate this. See [whatwg/fetch#526 (comment)](https://github.com/whatwg/fetch/issues/526#issuecomment-554604080) | ||
#### input | ||
@@ -67,3 +68,3 @@ | ||
if (response.status !== 200) { | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
@@ -70,0 +71,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
152
149
10986