-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Conversation
/** | ||
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. |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
Thanks for working on this. You also need to add the docs to the readme. |
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Friendly bump :) |
Closing for lack of response: #70 |
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