Skip to content

Retry calls using the Retry-After header. #6565

Answered by TkDodo
felipecauefraga asked this question in General
Discussion options

You must be logged in to vote

React Query knows nothing about http headers because it's not tied to http at all. It's a promise based state manager, which means you can do anything as long as your queryFn returns a resolved or rejected promise.

In your case, here's what I would do:

  • in the querFn, make your api call with your favourite tool.
  • catch errors inside the queryFn
  • look at the response headers and read the Retry-After header
  • re-throw a custom error that has a property retryAfter you can look at
  • implement the retryDelay function to look at the custom error and return a number in millis for how long to wait, something like:
useQuery({
  queryKey,
  queryFn,
  retryDelay: (failureCount, error) => error.retryAfte…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@felipecauefraga
Comment options

Answer selected by felipecauefraga
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants