[fix] apiClient 로직 수정 및 ErrorBoundary 추가#150
Conversation
Walkthrough토큰 갱신 로직을 리팩토링하여 접근성을 개선하고, Sentry ErrorBoundary를 활용해 에러 핸들링을 강화했습니다. 홈 페이지 주요 섹션들을 개별 에러 바운더리로 감싸 격리된 에러 처리를 구현했습니다. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 핵심 피드백src/apis/client.ts:
src/pages/Home/index.tsx:
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/pages/Home/index.tsx (1)
40-46: SectionErrorFallback에 재시도 기능 고려현재 fallback이 정적 UI만 렌더링합니다.
Sentry.ErrorBoundary는fallbackprop에 함수를 전달하면resetError를 받을 수 있어 사용자가 재시도할 수 있습니다.♻️ 재시도 버튼 추가 예시
-function SectionErrorFallback() { +function SectionErrorFallback({ resetError }: { resetError?: () => void }) { return ( <div className="border-indigo-5 flex w-full items-center justify-center rounded-lg border bg-white py-5"> <span className="text-sub2 text-gray-400">불러오는 중 오류가 발생했어요</span> + {resetError && ( + <button onClick={resetError} className="ml-2 text-sub2 text-primary"> + 재시도 + </button> + )} </div> ); }사용 시:
<Sentry.ErrorBoundary fallback={({ resetError }) => <SectionErrorFallback resetError={resetError} />}>🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/pages/Home/index.tsx` around lines 40 - 46, SectionErrorFallback currently renders a static error UI and doesn't support Sentry.ErrorBoundary's reset flow; update the SectionErrorFallback component to accept an optional resetError callback prop (e.g., function resetError?: () => void) and render a "Retry" button that calls resetError when provided so the boundary can be reset; ensure the component signature (SectionErrorFallback) and its usage with Sentry.ErrorBoundary's fallback={({ resetError }) => <SectionErrorFallback resetError={resetError} /> } are consistent and that the button is only shown when resetError is defined.src/apis/client.ts (1)
187-260: sendRequest와 sendRequestWithoutRetry 간 코드 중복두 함수가 URL 빌드, 헤더 구성, fetch 옵션, 에러 파싱 등 대부분의 로직을 공유합니다. 현재 동작에 문제는 없지만, 향후 유지보수 시 한쪽만 수정되는 실수가 발생할 수 있습니다.
♻️ 공통 로직 추출 제안
// 공통 로직을 내부 헬퍼로 추출 async function executeRequest<T, P extends object>( endPoint: string, options: FetchOptions<P>, timeout: number, handleAuth401: boolean ): Promise<T> { // 공통 fetch 로직 // handleAuth401이 true면 401에서 handleUnauthorized 호출 // false면 그냥 에러 throw }이렇게 하면
sendRequest와sendRequestWithoutRetry가 이 헬퍼를 호출하는 래퍼가 됩니다.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/apis/client.ts` around lines 187 - 260, sendRequest와 sendRequestWithoutRetry에서 URL 빌드, 헤더 구성, fetch 옵션 설정, 응답/에러 파싱 로직이 중복되므로 공통 로직을 내부 헬퍼로 추출하세요: 새 함수 executeRequest<T, P extends object>(endPoint: string, options: FetchOptions<P>, timeout: number, handleAuth401: boolean): Promise<T>에 URL 조립(joinUrl/buildQuery), 헤더 생성(콘텐츠 타입/Authorization via useAuthStore.getState().getAccessToken), AbortController + timeout, fetch 호출, parseResponse/parseErrorResponse 처리, 그리고 handleAuth401 플래그로 401 발생 시 기존의 handleUnauthorized 동작을 호출하거나 아니면 에러를 리턴하도록 구현한 뒤, 기존의 sendRequest와 sendRequestWithoutRetry는 필요한 handleAuth401 값만 전달하는 래퍼로 변경하세요.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/apis/client.ts`:
- Around line 187-260: sendRequest와 sendRequestWithoutRetry에서 URL 빌드, 헤더 구성,
fetch 옵션 설정, 응답/에러 파싱 로직이 중복되므로 공통 로직을 내부 헬퍼로 추출하세요: 새 함수 executeRequest<T, P
extends object>(endPoint: string, options: FetchOptions<P>, timeout: number,
handleAuth401: boolean): Promise<T>에 URL 조립(joinUrl/buildQuery), 헤더 생성(콘텐츠
타입/Authorization via useAuthStore.getState().getAccessToken), AbortController +
timeout, fetch 호출, parseResponse/parseErrorResponse 처리, 그리고 handleAuth401 플래그로
401 발생 시 기존의 handleUnauthorized 동작을 호출하거나 아니면 에러를 리턴하도록 구현한 뒤, 기존의 sendRequest와
sendRequestWithoutRetry는 필요한 handleAuth401 값만 전달하는 래퍼로 변경하세요.
In `@src/pages/Home/index.tsx`:
- Around line 40-46: SectionErrorFallback currently renders a static error UI
and doesn't support Sentry.ErrorBoundary's reset flow; update the
SectionErrorFallback component to accept an optional resetError callback prop
(e.g., function resetError?: () => void) and render a "Retry" button that calls
resetError when provided so the boundary can be reset; ensure the component
signature (SectionErrorFallback) and its usage with Sentry.ErrorBoundary's
fallback={({ resetError }) => <SectionErrorFallback resetError={resetError} /> }
are consistent and that the button is only shown when resetError is defined.
Summary by CodeRabbit
릴리스 노트