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

Using response headers in retry logic #63

Closed
Bazze opened this issue Oct 19, 2018 · 2 comments
Closed

Using response headers in retry logic #63

Bazze opened this issue Oct 19, 2018 · 2 comments

Comments

@Bazze
Copy link

Bazze commented Oct 19, 2018

Hey there!

Are there any possibilities to use information from the response of the failed request when defining the response delay? When rate limited for example, some APIs return a Retry-After header with a value indicating when you can try again (like Slack for example). I went through the source code quickly and from what I can see this is not possible at the moment, or?

Thanks

@rubennorte
Copy link
Contributor

rubennorte commented Oct 19, 2018

Sure, the second parameter of retryDelay is the error, which contains the response. You can just do:

axiosRetry(axios, { retryDelay: (retryCount, error) => {
  return parseFloat(error.response.headers['retry-after']) * 1000;
}});

You should check the value of the header, but you can get the general idea.

@Bazze
Copy link
Author

Bazze commented Oct 19, 2018

Amazing! Missed there was an extra param passed. Beautiful.

@Bazze Bazze closed this as completed Oct 19, 2018
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

No branches or pull requests

2 participants