#Query not retrying after axios 401 error

7 messages · Page 1 of 1 (latest)

keen cliff
#

I'm using useQuery to call an axios function to make an API call. When I load the relevant page, I can see the query making an initial attempt which results in a 401 response which axios raises as an error. (This happens because the very first call to this function doesn't yet have access to my API JWT for authentication.) The strange thing is that, after the initial 401 failure, the query does not retry (which is annoying, because it would then have access to my JWT token). Can anyone shed some light on why this might be happening? To clarify, Axios seems to be returning a failed promise after the 401 error, so react-query should be receiving that failed promise.

long canyon
#

I have the same issue

#

but I haven't found a fix for it still waiting or looking for the answer

forest scroll
#

Can you play around with enabled parameter? Will only fetch if the param is true.

long canyon
#

Yeah enabled is working can disabled the retry. But that's not the case because the problem when it is enabled let's assume we are using the session as the parameter for the enabled once the session expired that means the query will failed.

Now the problem is when the query failed it infinitely retries because of the 401 error even you set the retry: false or 0 it still fetching infinitely

gusty loom
#

show a minimal, runnable reproduction please. Per default, react-query will retry the API call 3 times with exponential backoff if the queryFn returns a failed promise

forest scroll
#

In my case, when the session expired, the server returns 417 code. I immediately clear my token, then the enabled param becomes false.