mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
Merge pull request #1061 from logto-io/charles-log-2877-stop-swr-retry-on-error-401-and-403
fix(console): stop swr retry on error 401 and 403
This commit is contained in:
commit
0cb407c0dd
2 changed files with 26 additions and 3 deletions
|
@ -12,7 +12,7 @@ import AppBoundary from './components/AppBoundary';
|
||||||
import AppContent from './components/AppContent';
|
import AppContent from './components/AppContent';
|
||||||
import ErrorBoundary from './components/ErrorBoundary';
|
import ErrorBoundary from './components/ErrorBoundary';
|
||||||
import Toast from './components/Toast';
|
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 initI18n from './i18n/init';
|
||||||
import ApiResourceDetails from './pages/ApiResourceDetails';
|
import ApiResourceDetails from './pages/ApiResourceDetails';
|
||||||
import ApiResources from './pages/ApiResources';
|
import ApiResources from './pages/ApiResources';
|
||||||
|
@ -33,11 +33,11 @@ import Users from './pages/Users';
|
||||||
void initI18n();
|
void initI18n();
|
||||||
|
|
||||||
const Main = () => {
|
const Main = () => {
|
||||||
const fetcher = useSwrFetcher();
|
const swrOptions = useSwrOptions();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<SWRConfig value={{ fetcher }}>
|
<SWRConfig value={swrOptions}>
|
||||||
<AppBoundary>
|
<AppBoundary>
|
||||||
<Toast />
|
<Toast />
|
||||||
<Routes>
|
<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…
Add table
Reference in a new issue