mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* update csv export text * fix pw tests * base layout and customization for home page and search results page * refactor rest of the pages * refactor AppError * move header padding to layout * move nextjs utils to separate folder * combine PageServer and Page * make useQueryClientConfig hook * add tests * remove unused var * fix envs for pw * fix pw tests
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { QueryClient } from '@tanstack/react-query';
|
|
import React from 'react';
|
|
|
|
import getErrorObjPayload from 'lib/errors/getErrorObjPayload';
|
|
import getErrorObjStatusCode from 'lib/errors/getErrorObjStatusCode';
|
|
|
|
export default function useQueryClientConfig() {
|
|
const [ queryClient ] = React.useState(() => new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
refetchOnWindowFocus: false,
|
|
retry: (failureCount, error) => {
|
|
const errorPayload = getErrorObjPayload<{ status: number }>(error);
|
|
const status = errorPayload?.status || getErrorObjStatusCode(error);
|
|
if (status && status >= 400 && status < 500) {
|
|
// don't do retry for client error responses
|
|
return false;
|
|
}
|
|
return failureCount < 2;
|
|
},
|
|
useErrorBoundary: (error) => {
|
|
const status = getErrorObjStatusCode(error);
|
|
// don't catch error for "Too many requests" response
|
|
return status === 429;
|
|
},
|
|
},
|
|
},
|
|
}));
|
|
|
|
return queryClient;
|
|
}
|