File tree Expand file tree Collapse file tree
clientBoundary/ErrorBoundary/GlobalErrorBoundary Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import { 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
79import { ErrorBoundary , ErrorHandler } from ".." ;
810import { GlobalErrorPage } from "./components/GlobalErrorPage" ;
911
1012export 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+
1623const networkErrorHandler : ErrorHandler = {
1724 isError : ( error ) => isNetworkError ( error ) ,
18- fallback : ( ) => < GlobalErrorPage /> ,
19- // TODO: network ErrorFallback 로 변경
25+ fallback : ( ) => < NetworkErrorFallback /> ,
2026} ;
2127
2228// TODO: 에러바운더리 수정
Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff 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+
3541export function isNetworkError ( error : Error ) : error is AxiosErrorResponse {
3642 return isAxiosErrorResponse ( error ) && ( error . response ?. status ?? 0 ) >= 400 ;
3743}
You can’t perform that action at this time.
0 commit comments