Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: client no longer delays when it wont retry #51

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,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) {
Copy link

@szpytfire-bbc szpytfire-bbc Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether it's worth leaving a comment explaining the rationale here? Perhaps even something as simple as (just so that you can take a quick glance at the code and understand what it does straight away):

// Only critical errors should retry

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah agree with this

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: critical errors. In this instance isn't it clear from the code that that's the case?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjewell47 there are a lot of other conditions chained in the if statement, but none of them matter unless the error is critical (which I think is the main fix/change in this PR). The comment would just highlight that importance, so that someone new to the code takes note 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks guys, we have added some jsdoc to make this a bit clearer

const delayBy = rejectedPromise(ctx.retryDelay);
return delayBy(err);
}
Expand Down