common retry function

This commit is contained in:
tom
2022-09-14 15:16:20 +03:00
parent bb24d7e1e8
commit e76ab2e20b
2 changed files with 10 additions and 8 deletions
-8
View File
@@ -18,13 +18,5 @@ export default function useFetchProfileInfo() {
return fetch('/api/account/profile');
}, {
refetchOnMount: false,
retry: (failureCount, error) => {
if (error?.error?.status === 401) {
// for unauthorized users don't do retry
return false;
}
return failureCount < 2;
},
});
}
+10
View File
@@ -4,6 +4,7 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import type { AppProps } from 'next/app';
import React, { useState } from 'react';
import type { ErrorType } from 'lib/hooks/useFetch';
import theme from 'theme';
function MyApp({ Component, pageProps }: AppProps) {
@@ -11,6 +12,15 @@ function MyApp({ Component, pageProps }: AppProps) {
defaultOptions: {
queries: {
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;
},
},
},
}));