From 763ffc236c1d23134bfcee190e75fa052b550270 Mon Sep 17 00:00:00 2001 From: wuzoo Date: Sun, 4 Aug 2024 19:58:22 +0900 Subject: [PATCH] #206 refactor: call handleTokenError when 401 error --- src/shared/page/errorPage/ErrorPage.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/shared/page/errorPage/ErrorPage.tsx b/src/shared/page/errorPage/ErrorPage.tsx index eff55469..71b555e0 100644 --- a/src/shared/page/errorPage/ErrorPage.tsx +++ b/src/shared/page/errorPage/ErrorPage.tsx @@ -5,6 +5,7 @@ import Button from '@/common/component/Button/Button'; import Flex from '@/common/component/Flex/Flex'; import Heading from '@/common/component/Heading/Heading'; import Text from '@/common/component/Text/Text'; +import { useTokenError } from '@/common/hook/useTokenError'; import { theme } from '@/common/style/theme/theme'; import { HTTP_ERROR_MESSAGE, HTTP_STATUS_CODE } from '@/shared/constant/api'; @@ -16,11 +17,19 @@ interface ErrorPageProps { } const ErrorPage = ({ statusCode = HTTP_STATUS_CODE.NOT_FOUND, resetError }: ErrorPageProps) => { - const isHTTPError = - statusCode === HTTP_STATUS_CODE.BAD_REQUEST || HTTP_STATUS_CODE.NOT_FOUND || HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR; + const isHTTPError = statusCode === HTTP_STATUS_CODE.CONTENT_TOO_LARGE ? HTTP_STATUS_CODE.BAD_REQUEST : statusCode; const navigate = useNavigate(); + const { handleTokenError } = useTokenError(); + + if (statusCode === HTTP_STATUS_CODE.UNAUTHORIZED) { + /** 모든 캐시 및 스토리지 clear 후 초기 화면으로 리다이렉트 */ + handleTokenError(); + + return null; + } + if (!isHTTPError) return null; return (