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:
parent
fbd7ac3a69
commit
db59e3c6d7
2 changed files with 26 additions and 3 deletions
|
@ -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>
|
||||
|
|
23
packages/console/src/hooks/use-swr-options.ts
Normal file
23
packages/console/src/hooks/use-swr-options.ts
Normal 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;
|
Loading…
Reference in a new issue