Skip to content

Commit

Permalink
feat: apiErrorboundary 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene028 committed Aug 22, 2024
1 parent 3f4ebce commit 5ad90a7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
"nanoid": "^5.0.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.13",
"react-hook-form": "^7.50.1",
"react-router-dom": "^6.22.1",
"react-toastify": "^10.0.4",
"wowds-icons": "^0.1.0",
"wowds-tokens": "^0.0.9",
"zustand": "^4.5.0",
"wowds-ui": "^0.1.9"
"wowds-ui": "^0.1.9",
"zustand": "^4.5.0"
},
"devDependencies": {
"@sentry/react": "^8.22.0",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 25 additions & 4 deletions src/components/ApiErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { PropsWithChildren } from 'react';

import { PropsWithChildren, PropsWithRef } from 'react';
import * as Sentry from '@sentry/react';
import { ErrorBoundary } from 'react-error-boundary';
import { useQueryClient } from '@tanstack/react-query';
import { AxiosError } from 'axios';
import { redirect } from 'react-router-dom';
import { toast } from 'react-toastify';
import RoutePath from '@/routes/routePath';
import NotFoundPage from '@/pages/NotFound';

type ErrorResponseType = {
errorCodeName: string;
errorMessage: string;
};

export default function ApiErrorBoundary({ children }: PropsWithChildren) {
export type ApiErrorBoundaryProps = PropsWithRef<
PropsWithChildren<ErrorBoundary>
>;

export default function ApiErrorBoundary({
children,
...rest
}: ApiErrorBoundaryProps) {
const queryClient = useQueryClient();

queryClient.getQueryCache().config = {
Expand All @@ -38,7 +47,19 @@ export default function ApiErrorBoundary({ children }: PropsWithChildren) {
toast.error(message);
break;
}

if (errorResponse) {
// eslint-disable-next-line import/namespace
Sentry.captureException(errorResponse, {});
}
}

return <>{children}</>;
return (
<ErrorBoundary
{...rest}
onError={(error) => handleError(error as AxiosError)}
fallbackRender={() => <NotFoundPage />}>
{children}
</ErrorBoundary>
);
}

0 comments on commit 5ad90a7

Please sign in to comment.