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

Implement retry with backoff to help dodge the 501 error #44

Merged
merged 1 commit into from
Jun 18, 2020

Conversation

gwynethsc
Copy link
Owner

on the development server as noted in issue#33. Also retries for all other errors. NOT a solution.

…opment server as noted in issue#33. Also retries for all other errors. NOT a solution.
Copy link
Collaborator

@sperzion sperzion left a comment

Choose a reason for hiding this comment

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

This is awesome! Great job figuring this out!


/**
* Upon failure, retry a function that returns a Promise up to a set number of times,
* with an exponentially increasing delay after each failure
Copy link
Collaborator

Choose a reason for hiding this comment

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

Technically, you're doubling the delay each time.

*/
function backoff(tries, fn, delay = 500) {
return fn().catch(error => {
if (tries > 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is good for this PR, but a slightly more sophisticated approach would be to check what type of error you're getting. If you know it's the intermittent kind, you could do the backoff, whereas if you know it's something that's never going to work no matter how many times you try, you could just stop.

})
.catch(error => console.error(error.message));
});
backoff(3, fn).catch(error => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, has this shown to work for you in your dev server?

@gwynethsc gwynethsc merged commit c7cba95 into master Jun 18, 2020
@gwynethsc gwynethsc deleted the error-501-et-workaround branch June 18, 2020 17:31
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