-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
에러 핸들링을 위한 컴포넌트 추가 및 적용 #546
Changes from 1 commit
b85ffa2
5fcdad5
fa83f97
73bcefc
d5629b4
ab62224
637fea6
e592dee
ce26068
8f39e61
34534f8
8f8bd53
9871b03
98acc12
13558c7
bea286a
15f1074
c5bbb90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,36 @@ | ||
import { MdOutlineErrorOutline } from 'react-icons/md'; | ||
import { Link } from 'react-router-dom'; | ||
import { Link, useRouteError } from 'react-router-dom'; | ||
import { keyframes, styled } from 'styled-components'; | ||
import Button from '../components/Button'; | ||
import AppError from '../errors/AppError'; | ||
|
||
const ErrorPage = () => { | ||
const error = useRouteError(); | ||
const message = error instanceof Error ? error.message : '알 수 없는 에러'; | ||
const isExpectedError = error instanceof AppError; | ||
|
||
return ( | ||
<Contaienr> | ||
<Container> | ||
<SentenceContainer> | ||
<MainSentence>다시 확인해주세요</MainSentence> | ||
<Sentence>요청하신 내용을 찾을 수 없어요</Sentence> | ||
<MainSentence>{isExpectedError ? '다시 확인해주세요' : '예기치 못한 에러가 발생하였습니다'}</MainSentence> | ||
{isExpectedError && <Sentence>{message}</Sentence>} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isExpectedError인 경우 사용자에게 표시할 만한 메세지가 나타날 것이기 때문에 적절한 코드라고 생각합니다! |
||
<ButtonContainer to="/"> | ||
<Button $fullWidth>홈으로 돌아가기</Button> | ||
</ButtonContainer> | ||
</SentenceContainer> | ||
<Icon /> | ||
</Contaienr> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default ErrorPage; | ||
|
||
const Contaienr = styled.section` | ||
const Container = styled.section` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
|
||
height: 100vh; | ||
height: 100%; | ||
padding-top: 150px; | ||
`; | ||
|
||
|
@@ -49,6 +54,7 @@ const MainSentence = styled.h1` | |
const Sentence = styled.span` | ||
font-size: ${({ theme }) => theme.fontSize.sm}; | ||
color: ${({ theme }) => theme.color.text.secondary}; | ||
text-align: center; | ||
`; | ||
|
||
const bounce = keyframes` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 router에 이런 훅이 있었나요? 덕분에 하나 배워갑니다!!👍
페이지 라우팅 중에 액션, 로더, 렌더링 중에 발생한 모든 오류를 반환한다는데 개발자가 따로 처리해야 할 작업이 없나요?
error에 할당하여 사용하면 끝인가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 그렇습니다. 그리고 그
error
를 어떻게 취급할 것인지는 개발자에게 달려있다고 할 수 있습니다.