diff --git a/lib/client.js b/lib/client.js index c980ab2..91979ec 100644 --- a/lib/client.js +++ b/lib/client.js @@ -353,6 +353,9 @@ function toRetry(err) { }; } +/** + * Retries only work on critical HTTP 5XX errors + */ function retry(fn, ctx) { ctx.retryAttempts = []; const maxAttempts = ctx.retries; @@ -360,7 +363,7 @@ function retry(fn, ctx) { function attempt(i) { return fn(ctx) .catch((err) => { - if (maxAttempts > 0) { + if (i < maxAttempts && isCriticalError(err) && ctx.retryDelay && ctx.retryDelay > 0) { const delayBy = rejectedPromise(ctx.retryDelay); return delayBy(err); } diff --git a/lib/context.js b/lib/context.js index 3d2be15..110d668 100644 --- a/lib/context.js +++ b/lib/context.js @@ -10,6 +10,9 @@ const USER_AGENT = `${packageInfo.name}/${packageInfo.version}`; class Context { constructor(defaults) { + /** + * Retries only work on critical HTTP 5XX errors + */ this.retries = 0; this.redirect = undefined; this._retryAttempts = [];