()
| 13 | import { getStore } from "./jotai"; |
| 14 | |
| 15 | export function buildQueryClient() { |
| 16 | const { reactQueryRetriesEnabled } = getStore().get(appConfigAtom); |
| 17 | |
| 18 | return new QueryClient({ |
| 19 | defaultOptions: { |
| 20 | queries: { |
| 21 | retry: (failureCount, error) => { |
| 22 | // Retries are disabled in test |
| 23 | if (!reactQueryRetriesEnabled) return false; |
| 24 | if (error.cause && (error.cause as any).status === 401) { |
| 25 | // When a request is unauthorized, we want to fail fast and refresh the token. |
| 26 | // In practice, the token should be refreshed by the middleware, so we should |
| 27 | // only see this on the actual refresh token call which doesn't have the |
| 28 | // middleware. |
| 29 | return false; |
| 30 | } |
| 31 | // Some custom error have a `skipQueryRetry` field to skip retries, |
| 32 | // e.g. NoRowsError. |
| 33 | if ( |
| 34 | error instanceof Error && |
| 35 | "skipQueryRetry" in error && |
| 36 | error.skipQueryRetry |
| 37 | ) { |
| 38 | return false; |
| 39 | } |
| 40 | return failureCount < 3; |
| 41 | }, |
| 42 | }, |
| 43 | }, |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | let queryClient = buildQueryClient(); |
| 48 |
no test coverage detected