Skip to content

Commit 1d14ad3

Browse files
committed
fix: AuthErrorFallback 추가
1 parent 1d3d2b4 commit 1d14ad3

4 files changed

Lines changed: 76 additions & 4 deletions

File tree

apps/ticket/src/shared/clientBoundary/ErrorBoundary/GlobalErrorBoundary/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@
22

33
import { Suspense } from "react";
44

5-
import { isNetworkError } from "@/shared/types/axioxError";
5+
import { AuthErrorFallback } from "@/shared/components/AuthErrorFallback";
6+
import { NetworkErrorFallback } from "@/shared/components/NetworkErrorFallback";
7+
import { isAuthError, isNetworkError } from "@/shared/types/axioxError";
68

79
import { ErrorBoundary, ErrorHandler } from "..";
810
import { GlobalErrorPage } from "./components/GlobalErrorPage";
911

1012
export const GlobalErrorBoundary = ({ children }: { children: React.ReactNode }) => (
11-
<ErrorBoundary handlers={[networkErrorHandler, globalErrorHandler]}>
13+
<ErrorBoundary handlers={[authErrorHandler, networkErrorHandler, globalErrorHandler]}>
1214
<Suspense>{children}</Suspense>
1315
</ErrorBoundary>
1416
);
1517

18+
const authErrorHandler: ErrorHandler = {
19+
isError: (error) => isAuthError(error),
20+
fallback: () => <AuthErrorFallback />,
21+
};
22+
1623
const networkErrorHandler: ErrorHandler = {
1724
isError: (error) => isNetworkError(error),
18-
fallback: () => <GlobalErrorPage />,
19-
// TODO: network ErrorFallback 로 변경
25+
fallback: () => <NetworkErrorFallback />,
2026
};
2127

2228
// TODO: 에러바운더리 수정
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"use client";
2+
3+
import { useEffect, useState } from "react";
4+
5+
import { LoadingWithLayout } from "../LoadingWithLayout";
6+
7+
export const AuthErrorFallback = () => {
8+
const [isLoading, setIsLoaidng] = useState(true);
9+
10+
useEffect(() => {
11+
const tokenReissue = async () => {
12+
await fetch("/api/reissue", {
13+
method: "POST",
14+
headers: {
15+
"Content-Type": "application/json",
16+
},
17+
credentials: "include",
18+
});
19+
20+
// 토큰 재발급 후 reload()
21+
window.location.reload();
22+
};
23+
24+
tokenReissue();
25+
}, []);
26+
27+
if (isLoading) {
28+
return <LoadingWithLayout />;
29+
}
30+
31+
return <div></div>;
32+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use client";
2+
3+
import { Button, Flex, Typography } from "@permit/design-system";
4+
5+
// TODO: 추후 변경
6+
export const NetworkErrorFallback = () => {
7+
return (
8+
<Flex
9+
direction="column"
10+
align="center"
11+
justify="center"
12+
gap={16}
13+
style={{ height: "calc(100vh - 150px)" }}
14+
>
15+
<Typography type="title24">서비스에 문제가 발생했어요</Typography>
16+
<Typography type="body14">잠시 후 다시 시도해주세요</Typography>
17+
<Button
18+
variant="primary"
19+
size="md"
20+
onClick={() => {
21+
window.location.href = "/";
22+
}}
23+
>
24+
홈으로 이동
25+
</Button>
26+
</Flex>
27+
);
28+
};

apps/ticket/src/shared/types/axioxError.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export function isNotAuthErrorResponse(error: unknown): error is AxiosErrorRespo
3232
);
3333
}
3434

35+
export function isAuthError(error: Error): error is AxiosErrorResponse {
36+
return (
37+
isAxiosErrorResponse(error) && error.response?.data.code === ERROR_CODE.ACCESS_TOKEN_EXPIRED
38+
);
39+
}
40+
3541
export function isNetworkError(error: Error): error is AxiosErrorResponse {
3642
return isAxiosErrorResponse(error) && (error.response?.status ?? 0) >= 400;
3743
}

0 commit comments

Comments
 (0)