All files / lib/providers QueryProvider.tsx

0% Statements 0/8
0% Branches 0/4
0% Functions 0/3
0% Lines 0/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                                                                                             
'use client';
 
import { QueryCache, QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { notification } from 'antd';
import axios from 'axios';
import React from 'react';
import * as Sentry from '@sentry/nextjs';
 
export default function QueryProvider({ children }: React.PropsWithChildren) {
  // 핸들링 되지 않은 에러를 처리하는 함수
  const handleError = React.useCallback((error: unknown) => {
    if (axios.isAxiosError(error)) {
      if (error.response?.data.message) {
        Sentry.captureException(error);
 
        notification.error({
          message: `오류 발생 [${error.response.data.errorTitle}]`,
          description: error.response.data.message,
          style: {
            wordBreak: 'keep-all'
          }
        });
      }
    }
  }, []);
 
  const [queryClient] = React.useState(
    () =>
      new QueryClient({
        defaultOptions: {
          queries: {
            retry: false,
            refetchOnWindowFocus: false
          },
          mutations: {
            onError: handleError
          }
        },
        queryCache: new QueryCache({
          onError: handleError
        })
      })
  );
 
  return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
}