-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add option to decide if retry should be attempted? #51
Comments
Hey I am trying to do same as you, can you please provide the sample code to get it to work thanks |
That's not so much boilerplate you can await retry(async bail => {
try {
const res = await client.users.create(intercomUser)
if ([400, 401, 409, 500].indexOf(res.statusCode) !== -1) {
// don't retry
bail(new Error(`Could not retry: status code ${res.statusCode}`))
}
} catch (error) {
// fail silently don't bail
if (/Multiple existing/.test(error.message)) {
return
}
throw (error)
}
}) EDIT: do not bail in the catch, somehow it throws unhandeld |
Not being able to "bail" in the catch is a huge limitation. Most of the time you would want to |
I know there's feature to bail out conditionally, but I think it would be useful to have a function that is called as soon as the operation fails, and the return value of that function should decide whether or not the next retry should happen.
So
if (!op.retry(err)) {
would just become something likeif (!options.shouldRetry(err) || !op.retry(err)) {
.Current alternative to this would be to have a try/catch in the
retrier
function, decide in catch, throw if need to retry, and swallow andbail
if needed. But this is a lot of boilerplate and can not be extracted into a separate function.While having a function in option would be much easier.
Did it make sense?
The text was updated successfully, but these errors were encountered: