Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
jpark0506
left a comment
There was a problem hiding this comment.
LGTM~ 좋은 코드를 작성해주셔서 많이 배울 수 있었습니다 고생하셨습니다!
| export default class ErrorBoundary extends Component< | ||
| React.PropsWithChildren<ErrorBoundaryProps>, | ||
| ErrorBoundaryState | ||
| > { | ||
| constructor(props: React.PropsWithChildren<ErrorBoundaryProps>) { | ||
| super(props); | ||
| this.state = { hasError: false }; | ||
| } | ||
|
|
||
| static getDerivedStateFromError(error: Error): ErrorBoundaryState { | ||
| return { hasError: true }; | ||
| } | ||
|
|
||
| render() { | ||
| if (this.state.hasError) { | ||
| return this.props.fallback; | ||
| } | ||
|
|
||
| return this.props.children; | ||
| } | ||
| } |
There was a problem hiding this comment.
static 메소드인 getDerivedStateFromError을 Override하는 방식이군요?? 커스텀 에러바운더리를 구현하시다니..대단합니다!! 하나 배워갑니다
| import React, { useCallback, useEffect, useState } from "react"; | ||
|
|
||
| type Fallback = { | ||
| [K in Exclude<ERROR_STATUS, ERROR_STATUS.INTERNAL_ERROR>]: { |
There was a problem hiding this comment.
enum 타입에서 특정 값을 제외하고 싶을 때 사용하는 용도로 사용하신 것 같은데, 다른 400에러가 추가될 수 있다는 점에서 확장성이 좋은 것 같습니다.
There was a problem hiding this comment.
감사합니다!
저도 이부분은 생성형 AI의 도움을 받아서 해결할 수 있었습니다
There was a problem hiding this comment.
예시까지 주셔서 코드 작성하는데 많은 도움이 될 것 같습니다!
#️⃣ 작업 내용
핵심 기능
커스텀 에러 바운더리 생성
POST 요청 시, 에러 핸들링 로직
useMutation이 기본적으로 입력받던, queryOptions, queryClient를 받고 추가적으로 fallback을 만들기 위한, 대제목과 소제목을 입력받습니다.
POST의 에러는 모달 형태로 보여줄 것이기에, mutation결과와 함께, Modal을 return 합니다.�
현재는 400, 404에 대한 처리만 진행이 되었지만 추후 확장될 수 있습니다.
useMutationError를 사용하려면
다음과 같이, fallback에 400, 404를 key로 하는 오브젝트를 전달합니다.
400과 404의 에러는 에러 바운더리에서 잡히는 것이 아닌, useMutationError에서 잡혀야 하기 때문에 fetch에서 response를 통해 다른 타입의 에러를 throw합니다.
response가 ok가 아닐 경우, status를 비교합니다. status가 400인 경우, BadRequestError를, 404인 경우, NotFoundError를 throw 합니다. 그 외의 경우에는 일반적은 Error를 throw합니다.
useMutationError에서는 useEffect 내부에서 mutation결과 error를 instanceof로 비교합니다.
동작 확인
2025-02-09.3.16.06.mov