From 595821081276fca471d4f9811196f522f6bf70d0 Mon Sep 17 00:00:00 2001 From: grace richardson Date: Fri, 13 Sep 2024 14:33:51 +0100 Subject: [PATCH] fix: client no longer delays when it wont retry (#51) * fix: client no longer delays when it wont retry * chore: added jsdoc retry critical error behaviour --------- Co-authored-by: chris stevens --- lib/client.js | 5 ++++- lib/context.js | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 = [];