Skip to content

Commit

Permalink
fix: client no longer delays when it wont retry (#51)
Browse files Browse the repository at this point in the history
* fix: client no longer delays when it wont retry

* chore: added jsdoc retry critical error behaviour

---------

Co-authored-by: chris stevens <chris.stevens01.ext@bbc.co.uk>
  • Loading branch information
graceannx and chr15stevens authored Sep 13, 2024
1 parent 0c04335 commit 5958210
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,17 @@ function toRetry(err) {
};
}

/**
* Retries only work on critical HTTP 5XX errors
*/
function retry(fn, ctx) {
ctx.retryAttempts = [];
const maxAttempts = ctx.retries;

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);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 5958210

Please sign in to comment.