Replies: 8 comments 28 replies
-
Hi i am also looking for this sort of behaviour. But I would like to handle this at a global level. Is it possible? |
Beta Was this translation helpful? Give feedback.
-
I'm not opposed to this, just need to wrap my head around it completely.
I get that if we want this globally, we'd need to use the defaultQueryFn. |
Beta Was this translation helpful? Give feedback.
-
The approach is interesting to get rid of some logic inside the |
Beta Was this translation helpful? Give feedback.
-
There is also a "proactive" solution if your access token is a JWT: |
Beta Was this translation helpful? Give feedback.
-
Hi @TkDodo Current retry function logic Can we make it so it throws (or at least fails) if retry is a function that does not return a I was debugging why it wasn't acting as expected then came to realise that it doesn't support // packages/query-core/src/retryer.ts
//...
// Do we need to retry the request?
const retry = config.retry ?? 3
const retryDelay = config.retryDelay ?? defaultRetryDelay
const delay =
typeof retryDelay === 'function'
? retryDelay(failureCount, error)
: retryDelay
const shouldRetry =
retry === true ||
(typeof retry === 'number' && failureCount < retry) ||
(typeof retry === 'function' && retry(failureCount, error)) can we change the last line to (typeof retry === 'function' && retry(failureCount, error) === true)
|
Beta Was this translation helpful? Give feedback.
-
Hey @TkDodo I tried I did test this in
|
Beta Was this translation helpful? Give feedback.
-
I also see a need for this but then on the hook level as well (not generic client). The current retry inside a hooks itself is currently only a number. But in our case 400 errors for example have explanations with So my question basically is can we have a retry where we can act on the status code / error response. |
Beta Was this translation helpful? Give feedback.
-
We would need async retry for advanced error handling. We are using websockets to invalidate queries to avoid staleness but in case of websocket timeouts, we want to have a backup invalidate mechanism if the usemutation throws specific error types. "Invalidation" here is not enough though and we actually need to await queryClient.refetchQueries which we can't do within the retry function. We ended up wrapping the usemutation and usequery hook for now to add this to the query/mutation fn but its not ideal. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
HI,
in my old project I was making an Axios interceptor and queuing all failed requests then fetch and refresh my
refreshToken
then retry all the failed requests.with React Query I don't need half of the setup i made before (thanks React Query <3)
but now I'm stuck with the refreshToken mechanism as I want to move it to React Query instead of Axios Interceptor
as the docs say in useQuery options
I think it would be a good idea to use async function for retry what do you think about this ?
Beta Was this translation helpful? Give feedback.
All reactions