queryClient: retry certain 5xx codes automatically

This commit is contained in:
Alex Gleason 2024-10-12 15:02:00 -05:00
parent 5a0713a02e
commit b348f30eea
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 19 additions and 1 deletions

View File

@ -1,12 +1,30 @@
import { QueryClient } from '@tanstack/react-query';
import { HTTPError } from 'soapbox/api/HTTPError';
/** HTTP response codes to retry. */
const RETRY_CODES = [502, 503, 504, 521, 522];
const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
staleTime: 60000, // 1 minute
gcTime: Infinity,
retry: false,
retry(failureCount: number, error: Error): boolean {
if (error instanceof HTTPError) {
const { response } = error;
// TODO: Implement Retry-After.
// const retryAfter = response.headers.get('Retry-After');
if (RETRY_CODES.includes(response.status)) {
return failureCount < 3;
}
}
return false;
},
},
},
});