Skip to content
Source
Sign inSign up
TanStack/query

Infinite Retry on 400 Status with React Query v5.83.0 #9437

Closedkingpipe(GitHub profile, opens in a new tab) opened this issue 3 comments

Describe the bug

I’ve set up a global QueryClient with custom retry logic for both queries and mutations. It correctly retries once on 401 Unauthorized, but when the server responds with a 400 Bad Request, React Query retries infinitely, which should not happen.

Your minimal, reproducible example

not have(

Steps to reproduce

export const queryClient = new QueryClient({ defaultOptions: { queries: { staleTime: 60 1000, cacheTime: 5 60 * 1000, refetchOnWindowFocus: false, refetchOnReconnect: false, onError: (error) => { console.error('Query Error:', error); }, retryDelay: 150, retry: async (failureCount, error) => { if (error?.response?.status === 401 && failureCount < 1) { await refreshAccessToken(); return true; } return false; }, }, mutations: { onError: (error) => { console.error('Mutation Error:', error); }, retryDelay: 150, retry: async (failureCount, error) => { if (error?.response?.status === 401 && failureCount < 1) { await refreshAccessToken(); return true; } return false; }, }, }, });

It's my global settings

Expected behavior

On HTTP 400 responses, the query should not retry at all.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

-OS: Windows -Browser: Chrome -Version:138.0.7204.101

Tanstack Query adapter

None

TanStack Query version

5.83.0

TypeScript version

No response

Additional context

No response

  1. TkDodocommented

    retry is not async, so returning a Promise will always evaluate to true

  2. TkDodo closed this

  3. TkDodo added labelsworks as designed

Sign in to join this conversation.