Commit e60f0513 authored by tom's avatar tom

common retry function

parent 881fd2bd
...@@ -18,13 +18,5 @@ export default function useFetchProfileInfo() { ...@@ -18,13 +18,5 @@ export default function useFetchProfileInfo() {
return fetch('/api/account/profile'); return fetch('/api/account/profile');
}, { }, {
refetchOnMount: false, refetchOnMount: false,
retry: (failureCount, error) => {
if (error?.error?.status === 401) {
// for unauthorized users don't do retry
return false;
}
return failureCount < 2;
},
}); });
} }
...@@ -4,6 +4,7 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; ...@@ -4,6 +4,7 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import type { AppProps } from 'next/app'; import type { AppProps } from 'next/app';
import React, { useState } from 'react'; import React, { useState } from 'react';
import type { ErrorType } from 'lib/hooks/useFetch';
import theme from 'theme'; import theme from 'theme';
function MyApp({ Component, pageProps }: AppProps) { function MyApp({ Component, pageProps }: AppProps) {
...@@ -11,6 +12,15 @@ function MyApp({ Component, pageProps }: AppProps) { ...@@ -11,6 +12,15 @@ function MyApp({ Component, pageProps }: AppProps) {
defaultOptions: { defaultOptions: {
queries: { queries: {
refetchOnWindowFocus: false, refetchOnWindowFocus: false,
retry: (failureCount, _error) => {
const error = _error as ErrorType<{ status: number }>;
if (error?.error?.status === 401) {
// for unauthorized users don't do retry
return false;
}
return failureCount < 2;
},
}, },
}, },
})); }));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment