-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
15-2 [FE] [에러 처리] 에러 상태코드 별 처리 (재요청, 에러페이지 등) #81
Conversation
…nto feature/error-handling
…nto feature/error-handling
static getDerivedStateFromError(error: Error) { | ||
return { error }; | ||
} | ||
|
||
componentDidCatch(error: Error, errorInfo: ErrorInfo): void { | ||
console.log('error: ', error); | ||
console.log('errorInfo: ', errorInfo); | ||
} |
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.
React에서 얼른 hook을 추가해줬으면 좋겠네요.
https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html
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.
ErrorBoundary가 Class component의 lifecycle을 사용하다보니.. 아직 hook이 없나봅니다. 🥲
(혹시 elastic 주소는 어떤걸까요?)
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.
<Route path={'*'} element={<GlobalErrorFallback />} /> | ||
</Routes> | ||
</Suspense> | ||
</ErrorBoundary> |
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.
좋네요👍
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.
에러 페이지 디자인도 맘에 들고, 계속해서 기존 코드를 리팩토링하고 다이어트 하는 부분이 좋은 것 같습니다. 고생하셨습니다.
@@ -17,26 +22,38 @@ const queryClient = new QueryClient({ | |||
refetchOnMount: false, | |||
refetchOnReconnect: false, | |||
staleTime: 5 * 60 * 1000, | |||
retry: (failureCount, error) => { | |||
if (error instanceof AxiosError) { | |||
return error.response?.status === 408 && failureCount <= 1 ? true : false; |
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.
failureCount 까지 체크하는 부분이 좋네요
개요
데이터를 불러와서 사용하는 컴포넌트를 Suspense와 ErrorBoundary로 감싸서 데이터 로딩이나 에러 발생 시 각각 로딩 컴포넌트와 에러 페이지를 보여주도록 했습니다.
react-query의 retry 기능을 이용해서 408(timeout) 에러 발생 시에는 3번 재요청 후 에러 페이지를 보여주고, 그 외의 에러는 재요청 없이 에러 페이지를 바로 보여주도록 설정했습니다.
컴포넌트에서 로딩, 에러 처리 로직을 분리함으로써 데이터를 불러오는 컴포넌트는 데이터를 불러오고 사용하는 데에만 집중할 수 있게 되었습니다.
추후 리팩토링을 통해 데이터를 불러오는 query 로직도 분리 예정입니다.
스크린샷
에러 페이지는 상태코드와 홈 이동 버튼을 보여주도록 간단하게 구성하였습니다.
작업사항
리뷰 요청사항