HR-ATS-Portal/frontend/src/lib/queryClient.js

26 lines
1023 B
JavaScript

import { QueryClient } from '@tanstack/react-query'
import { ApiError, SessionExpiredError } from './errors'
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
// A recruiter re-entering a screen within the minute gets cache, no spinner.
staleTime: 60_000,
gcTime: 15 * 60_000,
// This is an all-day tool. The prototype had no refetch-on-focus, and
// restriping every table on alt-tab would be a visible behaviour change.
refetchOnWindowFocus: false,
refetchOnReconnect: true,
retry: (count, err) => {
if (err instanceof SessionExpiredError) return false
// 401 is already handled by apiClient's refresh-and-retry; re-running
// the query would just repeat work. 403/404/422 will never succeed.
if (err instanceof ApiError && err.status >= 400 && err.status < 500) return false
return count < 2
},
retryDelay: (i) => Math.min(1000 * 2 ** i, 8000),
},
mutations: { retry: 0 },
},
})