diff --git a/packages/console/src/App.tsx b/packages/console/src/App.tsx index df369e07a..6db28baa6 100644 --- a/packages/console/src/App.tsx +++ b/packages/console/src/App.tsx @@ -12,7 +12,7 @@ import AppBoundary from './components/AppBoundary'; import AppContent from './components/AppContent'; import ErrorBoundary from './components/ErrorBoundary'; import Toast from './components/Toast'; -import useSwrFetcher from './hooks/use-swr-fetcher'; +import useSwrOptions from './hooks/use-swr-options'; import initI18n from './i18n/init'; import ApiResourceDetails from './pages/ApiResourceDetails'; import ApiResources from './pages/ApiResources'; @@ -33,11 +33,11 @@ import Users from './pages/Users'; void initI18n(); const Main = () => { - const fetcher = useSwrFetcher(); + const swrOptions = useSwrOptions(); return ( - + diff --git a/packages/console/src/hooks/use-swr-options.ts b/packages/console/src/hooks/use-swr-options.ts new file mode 100644 index 000000000..614cb2ce0 --- /dev/null +++ b/packages/console/src/hooks/use-swr-options.ts @@ -0,0 +1,23 @@ +import { SWRConfiguration } from 'swr'; + +import { RequestError } from './use-api'; +import useSwrFetcher from './use-swr-fetcher'; + +const useSwrOptions = (): SWRConfiguration => { + const fetcher = useSwrFetcher(); + + return { + fetcher, + shouldRetryOnError: (error: unknown) => { + if (error instanceof RequestError) { + const { status } = error; + + return status !== 401 && status !== 403; + } + + return true; + }, + }; +}; + +export default useSwrOptions;