-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
63 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const HTTP_STATUS_MESSAGE = { | ||
400: '잘못된 요청입니다.', | ||
401: '엑세스 권한이 없습니다.', | ||
403: '리소스에 엑세스할 수 없습니다.', | ||
404: '존재하지 않는 페이지입니다.', | ||
default: '서버 에러입니다', | ||
} as const; |
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 |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import { HTTP_STATUS_MESSAGE } from '@features/error/constants'; | ||
import { DefaultError, Query } from '@tanstack/react-query'; | ||
import toast from 'react-hot-toast'; | ||
|
||
type OnError = ( | ||
type handleError = ( | ||
error: DefaultError, | ||
query: Query<unknown, unknown, unknown> | ||
) => void; | ||
export const onError: OnError = (error, query) => { | ||
|
||
export const handleError: handleError = (error, query) => { | ||
if (query.state.data !== undefined) { | ||
toast.error(`백그라운드 데이터 가져오기 실패: ${error.message}`); | ||
return toast.error(`백그라운드 데이터 가져오기 실패: ${error.message}`); | ||
} | ||
}; | ||
|
||
type StatusCode = keyof typeof HTTP_STATUS_MESSAGE; | ||
|
||
export const getErrorMessage = (statusCode: number): string => { | ||
// 상태 코드가 객체의 키에 존재하는지 확인 | ||
return ( | ||
HTTP_STATUS_MESSAGE[statusCode as StatusCode] || HTTP_STATUS_MESSAGE.default | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,13 +1,30 @@ | ||
import { isAxiosError } from 'axios'; | ||
import { FallbackWrapper } from './styles'; | ||
import { FallbackProps } from 'react-error-boundary'; | ||
import { getErrorMessage } from '@features/error/service/errorUtils'; | ||
|
||
export default function Fallback({ error, resetErrorBoundary }: FallbackProps) { | ||
return ( | ||
<FallbackWrapper> | ||
<p>{error.toString()}</p> | ||
<p>오류가 발생했습니다.</p> | ||
<p>재시도 해주세요.</p> | ||
<button onClick={resetErrorBoundary}>재시도</button> | ||
</FallbackWrapper> | ||
); | ||
if (!isAxiosError(error)) { | ||
return <></>; | ||
} | ||
//스테이터스 코드가 있을 때때 | ||
if (error.status) { | ||
return ( | ||
<FallbackWrapper> | ||
<p>{getErrorMessage(error.status)}</p> | ||
<p>재시도 해주세요.</p> | ||
<button onClick={resetErrorBoundary}>재시도</button> | ||
</FallbackWrapper> | ||
); | ||
} | ||
|
||
if (error.code && error.code === 'ERR_NETWORK') { | ||
return ( | ||
<FallbackWrapper> | ||
<p>네트워크 에러가 발생했습니다.</p> | ||
<p>재시도 해주세요.</p> | ||
<button onClick={resetErrorBoundary}>재시도</button> | ||
</FallbackWrapper> | ||
); | ||
} | ||
} |
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 { Link } from 'react-router-dom'; | ||
|
||
export default function NotFoundPage() { | ||
return ( | ||
<div> | ||
<h1>404</h1> | ||
<p>페이지를 찾을 수 없습니다.</p> | ||
<Link to="/learn">홈으로 돌아가기</Link> | ||
</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