Skip to content
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

Merged
merged 18 commits into from
Oct 11, 2023
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions client/src/pages/ErrorPage.tsx
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';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 router에 이런 훅이 있었나요? 덕분에 하나 배워갑니다!!👍
페이지 라우팅 중에 액션, 로더, 렌더링 중에 발생한 모든 오류를 반환한다는데 개발자가 따로 처리해야 할 작업이 없나요?
error에 할당하여 사용하면 끝인가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 그렇습니다. 그리고 그 error를 어떻게 취급할 것인지는 개발자에게 달려있다고 할 수 있습니다.

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>}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isExpectedError가 true일 때, Error 인스턴스의 error.message를 렌더링하는데, 이 부분을 사용자에게 그대로 노출할 필요가 있을까요?

Copy link
Member Author

Choose a reason for hiding this comment

The 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;
`;

Expand All @@ -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`
Expand Down