-
Notifications
You must be signed in to change notification settings - Fork 2
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
[REFACTOR] 관리되지 않은 API 에러 분기 처리 개선 (UnhandledError) #408
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b83e741
refactor: 네트워크 에러와 관리되지 않는 에러 분기 처리 추가 #407
rbgksqkr c62e279
refactor: 에러 상태 코드 상수화 #407
rbgksqkr fcc2e93
refactor: 처리되지 않는 에러도 에러 폴백 UI를 보여주고 sentry로 추적 #407
rbgksqkr bcb9618
refactor: 불필요한 에러 조건문 제거 #407
rbgksqkr ea5707f
refactor: toast UI 여는 함수명을 명시적으로 showToast로 변경 #407
rbgksqkr 040e343
refactor: modal UI를 띄우는 함수명을 명시적으로 showModal로 변경 #407
rbgksqkr bdd52e9
fix: AsyncErrorFallback Error Type 조건문 명확하게 명시 #407
rbgksqkr 1304afe
merge: conflict 해결 #407
rbgksqkr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const SERVER_ERROR_STATUS = 500; | ||
export const NETWORK_ERROR_STATUS = 5001; | ||
export const UNHANDLED_ERROR_STATUS = 5002; |
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 |
---|---|---|
|
@@ -2,18 +2,20 @@ import { useQueryClient } from '@tanstack/react-query'; | |
import { PropsWithChildren } from 'react'; | ||
|
||
import AlertModal from '@/components/AlertModal/AlertModal'; | ||
import { NETWORK_ERROR_STATUS, SERVER_ERROR_STATUS } from '@/constants/errorStatus'; | ||
import useModal from '@/hooks/useModal'; | ||
import useToast from '@/hooks/useToast'; | ||
import { CustomError, NetworkError } from '@/utils/error'; | ||
import { CustomError, NetworkError, UnhandledError } from '@/utils/error'; | ||
|
||
const isServerError = (status: number) => status >= 500 && status !== 555; | ||
const isServerError = (status: number) => | ||
status >= SERVER_ERROR_STATUS && status !== NETWORK_ERROR_STATUS; | ||
|
||
// QueryClient는 모든 Provider에 공유되면서 공통 에러 핸들링 로직에 Toast와 Modal을 넣기 위해 setDefaultOptions 사용 | ||
// 테스트 환경에서 retry 값이 있을 경우 에러 폴백 테스트가 돌지 않아 분기 처리 | ||
const QueryClientDefaultOptionProvider = ({ children }: PropsWithChildren) => { | ||
const queryClient = useQueryClient(); | ||
const { show } = useToast(); | ||
const { show: showModal } = useModal(); | ||
const { showToast } = useToast(); | ||
const { showModal } = useModal(); | ||
|
||
queryClient.setDefaultOptions({ | ||
queries: { | ||
|
@@ -23,9 +25,14 @@ const QueryClientDefaultOptionProvider = ({ children }: PropsWithChildren) => { | |
mutations: { | ||
onError: (error) => { | ||
if (error instanceof NetworkError) { | ||
show(error.message); | ||
showToast(error.message); | ||
return; | ||
} | ||
|
||
if (error instanceof UnhandledError) { | ||
return; | ||
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. 💭 질문 💭해당 분기가 없으면 unhandledError도 모달이 뜨기 때문에 처리를 해 준 건가요? 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. 넵 맞습니당 |
||
} | ||
|
||
showModal(AlertModal, { title: '에러', message: error.message }); | ||
}, | ||
throwOnError: (err) => { | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💭 질문 💭
그럼 여기서 원래는 CustumError만 잡았는데 이제는 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 instanceof CustomError || error instanceof UnhandledError 로 잡는 게 맞는데 message만 사용하기도 하고, 한줄로 표현하고 싶어서 Error로 잡았던 것 같아요!
근데 썬데이말듣고 생각해보니 나중에 헷갈릴 수도 있을 것 같네용
error instanceof CustomError || error instanceof UnhandledError
로 명확하게 표현하겠습니다!