From 9ce0efa1ffc160de7f762c8509ad72fa5c9a5c37 Mon Sep 17 00:00:00 2001 From: robines Date: Tue, 17 Dec 2024 19:34:20 +0100 Subject: [PATCH 1/2] Handle 404 error responses in queryClient --- frontend/src/index.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index a11afa3bb..08124f054 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -4,6 +4,7 @@ import { AuthContextProvider } from '~/context/AuthContext'; import '~/global.scss'; import { QueryCache, QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; +import { AxiosError } from 'axios'; import { t } from 'i18next'; import { RouterProvider } from 'react-router-dom'; import { toast } from 'react-toastify'; @@ -17,12 +18,25 @@ const queryClient = new QueryClient({ queryCache: new QueryCache({ onError: (error, query) => { console.error(error); + + // Don't show toast on HTTP 404 errors + if (error instanceof AxiosError && error.response?.status === 404) { + return; + } + toast.error((query.meta?.errorMsg as string) ?? t(KEY.common_something_went_wrong)); }, }), defaultOptions: { queries: { - retry: 2, // default is 3 + retry: (failureCount, error) => { + // Don't retry on HTTP 404 responses + if (error instanceof AxiosError && error.response?.status === 404) { + return false; + } + // max 2 retries + return failureCount < 2; + }, }, }, }); From fb567741c14151df52b8db71377117d169f5f272 Mon Sep 17 00:00:00 2001 From: robines Date: Tue, 17 Dec 2024 19:38:44 +0100 Subject: [PATCH 2/2] Don't log either --- frontend/src/index.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index 08124f054..1eeffb49e 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -17,13 +17,12 @@ import { router } from '~/router/router'; const queryClient = new QueryClient({ queryCache: new QueryCache({ onError: (error, query) => { - console.error(error); - - // Don't show toast on HTTP 404 errors + // Ignore HTTP 404 responses if (error instanceof AxiosError && error.response?.status === 404) { return; } + console.error(error); toast.error((query.meta?.errorMsg as string) ?? t(KEY.common_something_went_wrong)); }, }),