generated from nim-od/softeer-mono-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from softeerbootcamp4th/TASK-185
[Feature][Task-185] Global Error Boundary 추가
- Loading branch information
Showing
14 changed files
with
134 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { PropsWithChildren, useMemo } from 'react'; | ||
import { ErrorBoundary, FallbackProps } from 'react-error-boundary'; | ||
import ErrorContainer from 'src/components/layout/ErrorContainer.tsx'; | ||
|
||
export default function GlobalErrorBoundary({ children }: PropsWithChildren) { | ||
return ( | ||
<ErrorBoundary FallbackComponent={ErrorFallback} onReset={window.location.reload}> | ||
{children} | ||
</ErrorBoundary> | ||
); | ||
} | ||
|
||
function ErrorFallback({ error, resetErrorBoundary }: FallbackProps) { | ||
const errorMessage = useMemo(() => { | ||
switch (error.status) { | ||
case 400: | ||
return '잘못된 요청입니다. 입력된 정보를 확인해주세요.'; | ||
case 401: | ||
return '로그인이 필요합니다. 다시 로그인해주세요.'; | ||
case 403: | ||
return '접근 권한이 없습니다. 권한을 확인해주세요.'; | ||
case 404: | ||
return '요청한 페이지를 찾을 수 없습니다.'; | ||
case 408: | ||
return '요청 시간이 초과되었습니다. 다시 시도해주세요.'; | ||
case 500: | ||
return '서버에 오류가 발생했습니다. 잠시 후 다시 시도해주세요.'; | ||
case 502: | ||
return '잘못된 게이트웨이입니다. 서비스가 불안정할 수 있습니다.'; | ||
case 503: | ||
return '서비스가 현재 이용 불가능합니다. 잠시 후 다시 시도해주세요.'; | ||
case 504: | ||
return '게이트웨이 시간 초과입니다. 다시 시도해주세요.'; | ||
default: | ||
return '무언가 문제가 발생했어요!'; | ||
} | ||
}, [error]); | ||
|
||
return <ErrorContainer errorMessage={errorMessage} reset={resetErrorBoundary} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Button from 'src/components/common/Button.tsx'; | ||
|
||
interface ErrorFallbackProps { | ||
errorMessage: string; | ||
reset: () => void; | ||
} | ||
|
||
export default function ErrorContainer({ errorMessage, reset }: ErrorFallbackProps) { | ||
return ( | ||
<div | ||
role="alert" | ||
className="w-screen flex h-screen flex-col items-center gap-15 justify-center" | ||
> | ||
<img src="/images/fcfs/result/wrong.png" alt="오류 발생 이미지" /> | ||
<div className="flex flex-col items-center gap-5"> | ||
<h4>{errorMessage}</h4> | ||
<Button onClick={reset}>새로 고침 하기</Button> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
import ErrorContainer from 'src/components/layout/ErrorContainer.tsx'; | ||
import RoutePaths from 'src/constants/routePath.ts'; | ||
|
||
export default function ErrorPage() { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<ErrorContainer errorMessage="문제가 발생했어요!" reset={() => navigate(RoutePaths.Home)} /> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters