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

Adding automatic retries on network and 5xx errors #61

Merged
merged 5 commits into from
Feb 20, 2019

Conversation

Amit-A
Copy link
Collaborator

@Amit-A Amit-A commented Feb 12, 2019

Retries 3 times by default, and only on network errors and 5xx errors on indempotent requests (GET, HEAD, OPTIONS, PUT, or DELETE).

Retries 3 times by default, and only on network errors and 5xx errors on indempotent requests (GET, HEAD, OPTIONS, PUT, or DELETE).
@Amit-A
Copy link
Collaborator Author

Amit-A commented Feb 12, 2019

This should fix this issue.

lib/b2.js Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@haywirez
Copy link
Contributor

Thanks for this simple fix, saves me a lot of unnecessary headaches! Would be great to add an error handling example in the README

@yakovkhalinsky
Copy link
Owner

Just the one question from me, otherwise I really like the option of replacing the axios instance.

@Amit-A
Copy link
Collaborator Author

Amit-A commented Feb 17, 2019

@yakovkhalinsky what is the question?

@yakovkhalinsky
Copy link
Owner

@Amit-A just wonder why you wrap the object with Object.assign rather than just passing it to the function?

@Amit-A
Copy link
Collaborator Author

Amit-A commented Feb 17, 2019

@yakovkhalinsky Object.assign(defaultObj, overrideObj) allows us to set default values in defaultObj which the user can override or add additional values. In this case we're setting the default number of retries to 3 { retries: 3 } which the user can override if they wish.

allows an optional axios config object that overrides the default axios config
creates new axios instance so that axios-retry isn't injected into the user's code if they also use axios
*/
const axiosClient = axios.create(Object.assign({ /* no defaults for now */ }, options.axios));
Copy link
Owner

Choose a reason for hiding this comment

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

Just curious about the reasoning for using Object.assign() here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh it's not really necessary in that case - it's just there so that we can add defaults in the future if necessary.

@Amit-A Amit-A merged commit 4d41f5f into yakovkhalinsky:master Feb 20, 2019
@yakovkhalinsky yakovkhalinsky added this to the 1.3.0 release milestone Feb 20, 2019
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.

None yet

5 participants