kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
queryClient: retry certain 5xx codes automatically
rodzic
5a0713a02e
commit
b348f30eea
|
@ -1,12 +1,30 @@
|
||||||
import { QueryClient } from '@tanstack/react-query';
|
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({
|
const queryClient = new QueryClient({
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
queries: {
|
queries: {
|
||||||
refetchOnWindowFocus: false,
|
refetchOnWindowFocus: false,
|
||||||
staleTime: 60000, // 1 minute
|
staleTime: 60000, // 1 minute
|
||||||
gcTime: Infinity,
|
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;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Ładowanie…
Reference in New Issue