Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Fix error response after several retries
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Mar 7, 2019
1 parent 809e8f7 commit 5bf4bc9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ function setup(fetch) {

return retry(async (bail, attempt) => {
const {method = 'GET'} = opts;
const isRetry = attempt < retryOpts.retries;
try {
// this will be retried
const res = await fetch(url, opts);
debug('status %d', res.status);
if (res.status >= 500 && res.status < 600) {
if (res.status >= 500 && res.status < 600 && isRetry) {
const err = new Error(res.statusText);
err.code = err.status = err.statusCode = res.status;
err.url = url;
Expand All @@ -45,7 +46,7 @@ function setup(fetch) {
return res;
}
} catch (err) {
debug(`${method} ${url} error (${err.status}). ${attempt < MAX_RETRIES ? 'retrying' : ''}`, err);
debug(`${method} ${url} error (${err.status}). ${isRetry ? 'retrying' : ''}`, err);
throw err;
}
}, retryOpts)
Expand Down

0 comments on commit 5bf4bc9

Please sign in to comment.