Skip to content

Ability to customize whether an error should be retried #67

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

Closed
wants to merge 2 commits into from

Conversation

Akkuma
Copy link

@Akkuma Akkuma commented Jul 29, 2022

I saw #46 and thought it would be a quick addition.

I've added tests, exported the original retry logic, and added the types.

Fixes #46

/**
Callback invoked on to determine whether a retry should occur. Receives the error thrown by `input` as the first argument with properties `attemptNumber` and `retriesLeft` which indicate the current attempt number and the number of attempts left, respectively.

`shouldRetry` will not allow AbortError overrides. It allows overriding the default retry logic (aborting on TypeError's that aren't network errors) for all other errors.
Copy link
Owner

Choose a reason for hiding this comment

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

shouldRetry will not allow AbortError overrides.

I don't think it's clear enough what this means. I would spell it out more explicitly. That this cannot be used to prevent an aborted operation (AbortError).

Copy link
Author

Choose a reason for hiding this comment

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

Got it! Will update this to make it clear on what this does and how it behaves.

});
```

If the `onFailedAttempt` function throws, all retries will be aborted and the original promise will reject with the thrown error.
Copy link
Owner

Choose a reason for hiding this comment

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

This should be placed above the example.

@@ -17,6 +17,8 @@ export interface FailedAttemptError extends Error {
readonly retriesLeft: number;
}

export function shouldRetry(error: FailedAttemptError): boolean;
Copy link
Owner

Choose a reason for hiding this comment

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

This needs a doc comment about its purpose is.

@sindresorhus
Copy link
Owner

Thanks for working on this.

You also need to add the docs to the readme.

Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
@sindresorhus
Copy link
Owner

Friendly bump :)

@sindresorhus
Copy link
Owner

Closing for lack of response: #70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants