From f652b44c8b7ce0c62ca101f9e5d92904f27ebd92 Mon Sep 17 00:00:00 2001 From: Karolis Uzkuraitis Date: Tue, 13 Jul 2021 00:41:54 +0300 Subject: [PATCH 1/3] Firefox network error contains "." at the end --- index.js | 2 +- test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index b502b84..9827ea6 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const retry = require('retry'); const networkErrorMsgs = [ 'Failed to fetch', // Chrome - 'NetworkError when attempting to fetch resource', // Firefox + 'NetworkError when attempting to fetch resource.', // Firefox 'The Internet connection appears to be offline', // Safari 'Network request failed' // `cross-fetch` ]; diff --git a/test.js b/test.js index fdd2a00..5e1807a 100644 --- a/test.js +++ b/test.js @@ -62,6 +62,20 @@ test('retry on TypeError - failed to fetch', async t => { t.is(index, 3); }); +test('retry on TypeError - NetworkError when attempting to fetch resource.', async t => { + const typeErrorFixture = new TypeError('NetworkError when attempting to fetch resource.'); + let index = 0; + + const returnValue = await pRetry(async attemptNumber => { + await delay(40); + index++; + return attemptNumber === 3 ? fixture : Promise.reject(typeErrorFixture); + }); + + t.is(returnValue, fixture); + t.is(index, 3); +}); + test('AbortError - string', t => { const error = new pRetry.AbortError('fixture').originalError; t.is(error.constructor.name, 'Error'); From a8222120d424558cc5a75cce66907586dda805cd Mon Sep 17 00:00:00 2001 From: Karolis Uzkuraitis Date: Tue, 13 Jul 2021 07:59:05 +0300 Subject: [PATCH 2/3] Added dot for safari message too The Internet connection appears to be offline. --- index.js | 2 +- test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9827ea6..3679399 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ 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 + 'The Internet connection appears to be offline.', // Safari 'Network request failed' // `cross-fetch` ]; diff --git a/test.js b/test.js index 5e1807a..1eebf33 100644 --- a/test.js +++ b/test.js @@ -76,6 +76,20 @@ test('retry on TypeError - NetworkError when attempting to fetch resource.', asy t.is(index, 3); }); +test('retry on TypeError - The Internet connection appears to be offline.', async t => { + const typeErrorFixture = new TypeError('The Internet connection appears to be offline.'); + let index = 0; + + const returnValue = await pRetry(async attemptNumber => { + await delay(40); + index++; + return attemptNumber === 3 ? fixture : Promise.reject(typeErrorFixture); + }); + + t.is(returnValue, fixture); + t.is(index, 3); +}); + test('AbortError - string', t => { const error = new pRetry.AbortError('fixture').originalError; t.is(error.constructor.name, 'Error'); From 946aff9b4dc2219c88d3b4fbd399331313d80500 Mon Sep 17 00:00:00 2001 From: Karolis Uzkuraitis Date: Wed, 14 Jul 2021 01:41:06 +0300 Subject: [PATCH 3/3] Removed unnecessary tests --- test.js | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/test.js b/test.js index 1eebf33..fdd2a00 100644 --- a/test.js +++ b/test.js @@ -62,34 +62,6 @@ test('retry on TypeError - failed to fetch', async t => { t.is(index, 3); }); -test('retry on TypeError - NetworkError when attempting to fetch resource.', async t => { - const typeErrorFixture = new TypeError('NetworkError when attempting to fetch resource.'); - let index = 0; - - const returnValue = await pRetry(async attemptNumber => { - await delay(40); - index++; - return attemptNumber === 3 ? fixture : Promise.reject(typeErrorFixture); - }); - - t.is(returnValue, fixture); - t.is(index, 3); -}); - -test('retry on TypeError - The Internet connection appears to be offline.', async t => { - const typeErrorFixture = new TypeError('The Internet connection appears to be offline.'); - let index = 0; - - const returnValue = await pRetry(async attemptNumber => { - await delay(40); - index++; - return attemptNumber === 3 ? fixture : Promise.reject(typeErrorFixture); - }); - - t.is(returnValue, fixture); - t.is(index, 3); -}); - test('AbortError - string', t => { const error = new pRetry.AbortError('fixture').originalError; t.is(error.constructor.name, 'Error');