0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

fix(console): stop swr retry on error 401 and 403

This commit is contained in:
Charles Zhao 2022-06-07 11:59:17 +08:00
parent fbd7ac3a69
commit db59e3c6d7
No known key found for this signature in database
GPG key ID: 4858774754C92DF2
2 changed files with 26 additions and 3 deletions

View file

@ -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 (
<ErrorBoundary>
<SWRConfig value={{ fetcher }}>
<SWRConfig value={swrOptions}>
<AppBoundary>
<Toast />
<Routes>

View file

@ -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;