Skip to content

[Fix] Axios 리팩토링 로직 오류 수정#387

Merged
Chiman2937 merged 6 commits intomainfrom
chiyoung-refactor/axios
Feb 20, 2026
Merged

[Fix] Axios 리팩토링 로직 오류 수정#387
Chiman2937 merged 6 commits intomainfrom
chiyoung-refactor/axios

Conversation

@Chiman2937
Copy link
Member

@Chiman2937 Chiman2937 commented Feb 20, 2026

📝 변경 사항

Axios 리팩토링 후속 버그픽스 변경사항

브랜치: chiyoung-refactor/axios
커밋 범위: 0bce8cb ~ 92a945d (5개 커밋)
변경 파일: 11개 (55 additions, 55 deletions)


커밋 히스토리

커밋 메시지
0bce8cb fix: chat service - createDMChatRoom의 api 참조경로 오류 수정
5d957a1 fix: next 보안 취약점 개선을 위한 버전 업데이트(16.1.6)
489ef52 fix: authAPI - errorResponse return에서 throw로 수정
45acf52 fix: 순환참조 해결을 위한 api/core/index.ts 삭제(Barrel Export 패턴 제거)
92a945d fix: baseAPI - window.location.href 이후 return 추가(error throw 제거)

1. chat-service createDMChatRoom URL 프리픽스 누락 수정

/chat/dm/api/v1/chat/dm으로 수정.

// Before
createDMChatRoom: async (payloads: CreateDMPayloads) => {
  return baseAPI.post<ChattingRoom>('/chat/dm', payloads);
},

// After
createDMChatRoom: async (payloads: CreateDMPayloads) => {
  return baseAPI.post<ChattingRoom>('/api/v1/chat/dm', payloads);
},

2. Next.js 보안 취약점 개선을 위한 버전 업데이트

package.json에서 Next.js 버전 업데이트: 16.0.1016.1.6

기존 사용 중이던 Next.js 16.0.x에 아래 CVE가 존재하여 즉시 업그레이드 진행.

CVE 심각도 유형 설명
CVE-2025-55184 고위험 DoS React Server Components에서 발견된 서비스 거부 취약점
CVE-2025-55183 중위험 소스코드 노출 React Server Components에서 발견된 소스코드 노출 취약점
CVE-2025-66478 CVSS 10.0 (Critical) 원격 코드 실행(RCE) React Server Components 프로토콜에서 발견된 치명적 취약점. 모든 15.x 및 16.x 사용자에게 즉시 업그레이드 권고

현재 최신 안정 버전은 Next.js 16.1이며, 위 보안 패치 외에도 Turbopack 파일 시스템 캐싱 안정화 등의 개선이 포함되어 있음.


3. authAPI - 에러 응답 returnthrow 수정

src/api/core/auth/index.ts의 response interceptor에서 에러 응답을 return하던 것을 throw로 수정.

// Before - 에러가 정상 응답처럼 반환됨
async (error) => {
  return new CommonErrorResponse(error.response?.data);
},

// After - 에러가 정상적으로 throw됨
async (error) => {
  throw new CommonErrorResponse(error.response?.data);
},

return으로 처리하면 호출부에서 에러를 catch하지 못하고 정상 응답으로 처리되는 문제가 있었음. throw로 변경하여 try-catch 또는 .catch()로 에러를 정상적으로 핸들링할 수 있도록 수정.


4. 순환참조 해결 - Barrel Export 파일 삭제

src/api/core/index.ts (re-export 파일) 삭제 및 모든 서비스에서 직접 경로로 import하도록 변경.

순환참조 발생 원인

baseAPI (core/base/index.ts)
  → import { API } from '../..'     (api/index.ts)
  → import services                  (api/service/*)
  → import { baseAPI } from '@/api/core'  (core/index.ts)
  → import { baseAPI } from './base' (core/base/index.ts)  ← 순환!

해결 방법

core/index.ts (Barrel Export) 삭제 후, 각 서비스에서 직접 경로로 import.

// Before - Barrel Export를 통한 import
import { baseAPI } from '@/api/core';
import { authAPI } from '@/api/core';

// After - 직접 경로 import
import { baseAPI } from '@/api/core/base';
import { authAPI } from '@/api/core/auth';

영향받은 파일

서비스 Before After
auth-service @/api/core @/api/core/auth
chat-service @/api/core @/api/core/base
follower-service @/api/core @/api/core/base
group-service @/api/core @/api/core/base
notification-service @/api/core @/api/core/base
user-service @/api/core @/api/core/base

5. baseAPI - window.location.href 이후 return 추가

src/api/core/base/index.ts의 401 에러 처리에서 window.location.href 리다이렉트 이후 return문을 추가하여 이후 코드(throw errorResponse)가 실행되지 않도록 수정.

// Before - 리다이렉트 후에도 throw errorResponse가 실행됨
if (status === 401 && !originalRequest._retry) {
  // ...
  } catch (refreshError) {
    if (isServer) {
      throw refreshError;
    } else {
      const currentPath = window.location.pathname + window.location.search;
      window.location.href = `/login?error=...`;
      // ⚠️ 여기서 멈추지 않고 아래 throw errorResponse까지 실행됨
    }
  }
}
throw errorResponse;  // ← 리다이렉트 후에도 도달

// After - return으로 이후 코드 실행 방지
window.location.href = `/login?error=...`;
return;  // ✅ 이후 throw errorResponse 실행 방지

변경된 파일 목록

파일 변경 유형
package.json 수정 (next 16.0.10 → 16.1.6)
pnpm-lock.yaml 수정 (lock file 갱신)
src/api/core/index.ts 삭제 (Barrel Export 제거)
src/api/core/auth/index.ts 수정 (return → throw)
src/api/core/base/index.ts 수정 (return 추가)
src/api/service/auth-service/index.ts 수정 (import 경로 변경)
src/api/service/chat-service/index.ts 수정 (import 경로 변경, URL 수정)
src/api/service/follower-service/index.ts 수정 (import 경로 변경)
src/api/service/group-service/index.ts 수정 (import 경로 변경)
src/api/service/notification-service/index.ts 수정 (import 경로 변경)
src/api/service/user-service/index.ts 수정 (import 경로 변경)

🔗 관련 이슈

Closes #


🧪 테스트 방법

  • 수동 테스트 검증(로컬 환경)
  • 유닛 테스트 검증
  • 통합 테스트 검증

📸 스크린샷 (선택)


📋 체크리스트

  • 관련 문서를 업데이트했습니다 (필요한 경우)
  • 테스트를 추가/수정했습니다 (필요한 경우)
  • Breaking change가 있다면 명시했습니다

💬 추가 코멘트


CodeRabbit Review는 자동으로 실행되지 않습니다.

Review를 실행하려면 comment에 아래와 같이 작성해주세요

@coderabbitai review

Summary by CodeRabbit

릴리스 노트

  • 업데이트

    • Next.js 버전을 최신으로 업그레이드했습니다.
  • 버그 수정

    • API 인증 오류 처리 로직을 개선하였습니다.
    • 권한 없음 오류 발생 시 리다이렉션 후 추가 요청 처리를 방지하도록 수정하였습니다.

@github-actions
Copy link

github-actions bot commented Feb 20, 2026

🎭 Playwright Report

E2E Test가 성공적으로 완료되었습니다.

Test 요약 내용을 확인해주세요.

Status Build Log Updated (UTC)
✅ Ready View Build 2026-02-20 08:41:33

📊 Test Summary

  • ✅ Passed: 3
  • ❌ Failed: 0
  • ⏱️ Duration: 38.1s

📜 Test Details

✅ Passed Tests (3)
  • profile.test.ts (3)
    • [chromium] 존재하지 않는 프로필 페이지로 접속 시 404 redirect 되는 지 테스트
    • [firefox] 존재하지 않는 프로필 페이지로 접속 시 404 redirect 되는 지 테스트
    • [webkit] 존재하지 않는 프로필 페이지로 접속 시 404 redirect 되는 지 테스트

@github-actions github-actions bot requested a review from wooktori February 20, 2026 08:31
@github-actions
Copy link

github-actions bot commented Feb 20, 2026

🎨 Storybook Report

변경 사항이 없습니다

모든 Story가 이전 빌드와 동일합니다.

Status Storybook Build Log Updated (UTC)
✅ Unchanged View Storybook View Build 2026-02-20 08:41:52

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Next.js 의존성을 16.0.10에서 16.1.6으로 업데이트하고, API 모듈 구조를 재정렬했습니다. 핵심 API 인터페이스의 재내보내기를 제거하고 서비스 파일들의 import 경로를 업데이트했으며, 인증 및 기본 인터셉터의 에러 처리 로직을 조정했습니다.

Changes

Cohort / File(s) Summary
Dependency Update
package.json
Next.js 16.0.10에서 16.1.6으로 버전 업그레이드
API Core Module Restructuring
src/api/core/index.ts
authAPI와 baseAPI의 재내보내기 제거로 공개 모듈 인터페이스 축소
Auth Interceptor Logic
src/api/core/auth/index.ts
응답 인터셉터의 에러 핸들러를 CommonErrorResponse 반환에서 에러 객체 throw로 변경하여 Promise 체인 처리 방식 수정
Base Interceptor Logic
src/api/core/base/index.ts
클라이언트 사이드 로그인 페이지 리다이렉트 후 명시적 early return 추가로 원본 요청 재처리 방지
Service Import Path Updates
src/api/service/auth-service/index.ts, src/api/service/chat-service/index.ts, src/api/service/follower-service/index.ts, src/api/service/group-service/index.ts, src/api/service/notification-service/index.ts, src/api/service/user-service/index.ts
baseAPI 및 authAPI import 경로를 재내보내기 제거에 맞춰 @/api/core에서 @/api/core/auth 또는 @/api/core/base로 변경

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

Ready For Review!

Suggested reviewers

  • wooktori
  • yoorli

Poem

🐰 모듈 구조 정리하고, 경로 재정렬하니,
API 인터셉터가 더욱 명확해졌네요.
Next.js도 버전 업, 에러 처리도 탄탄히,
코드의 흐름이 이제 한결 깔끔해요! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목 '[Fix] Axios 리팩토링 로직 오류 수정'은 변경사항의 핵심을 명확하게 요약하고 있으며, 실제 변경내용(버그 수정, 순환참조 해결, 에러 처리 개선)과 일치합니다.
Description check ✅ Passed PR 설명은 템플릿 구조를 따르고 있으며, 변경사항을 상세히 설명하고 있습니다. 다만 테스트 검증과 체크리스트 항목이 미완성 상태입니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chiyoung-refactor/axios

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Feb 20, 2026

🚀 PR Preview Report

Build가 성공적으로 완료되었습니다.

Preview에서 변경사항을 확인하세요.

Status Preview Build Log Updated (UTC)
✅ Ready Visit Preview View Logs 2026-02-20 08:41:25

@github-actions
Copy link

github-actions bot commented Feb 20, 2026

📊 Coverage Report

Status Build Log Updated (UTC)
✅ Ready View Build 2026-02-20 08:40:13

📉 #387main에 병합하면 coverage가 0.01% 감소합니다.

Coverage 요약

@@             Coverage Diff             @@
##             main     #387       +/-   ##
===========================================
- Coverage   35.69%   35.68%    -0.01%     
===========================================
  Files         263      262        -1     
  Lines       12141    12140        -1     
  Branches      477      477         0     
===========================================
- Hits         4334     4332        -2     
+ Misses       7807     7808        +1     

영향받은 파일

파일 Coverage 변화
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/api/core/base/index.ts 43.85% (-0.79%) ⬇️

@Chiman2937
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/api/core/base/index.ts (1)

40-43: 401 리다이렉트 이후 throw 실행 방지 수정 확인

window.location.href 설정 후 return;을 추가하여 Line 53의 throw errorResponse가 실행되지 않도록 한 수정은 올바릅니다.

다만, return;은 Axios 인터셉터 Promise를 undefined로 resolve 시킵니다. 페이지 이동 속도가 느린 환경에서 await baseAPI.someMethod()의 반환값을 사용하는 코드가 이어 실행될 경우, 에러 없이 undefined를 받아 TypeError가 발생할 수 있습니다. 리다이렉트 중 이후 코드가 아예 실행되지 않도록 절대 settle되지 않는 Promise를 반환하는 방법도 고려할 수 있습니다.

💡 선택적 개선안
  window.location.href = `/login?error=unauthorized&path=${encodeURIComponent(currentPath)}`;
- return;
+ return new Promise(() => {});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/api/core/base/index.ts` around lines 40 - 43, 현재 Axios 응답 인터셉터에서 401 발생 시
window.location.href 설정 후 단순히 `return;` 하면 Promise가 정상 resolve(undefined)되어 이후
`await baseAPI.someMethod()` 호출 코드가 계속 실행되어 TypeError를 일으킬 수 있으므로, 401 처리
분기(인터셉터 코드에서 `window.location.href = ...` 직후)에 단순 return 대신 절대 settle되지 않는
Promise를 반환하도록 바꿔 인터셉터가 후속 코드로 이어지지 않게 하세요; 예시로 해당 분기에서 `return new Promise(()
=> {})`를 반환하도록 변경하여 `errorResponse`를 throw 하거나 undefined를 반환해 후속 코드가 실행되는 상황을 모두
방지하세요 (참조 심볼: axios 응답 인터셉터, errorResponse, baseAPI.someMethod()).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@package.json`:
- Line 57: Update the devDependency "eslint-config-next" to match the "next"
version (change "eslint-config-next" from 16.0.1 to 16.1.6) so both packages use
the same version; after updating the "eslint-config-next" entry in package.json,
run your package manager (npm/yarn/pnpm) to reinstall and update the lockfile to
ensure ESLint rules align with Next.js.

---

Nitpick comments:
In `@src/api/core/base/index.ts`:
- Around line 40-43: 현재 Axios 응답 인터셉터에서 401 발생 시 window.location.href 설정 후 단순히
`return;` 하면 Promise가 정상 resolve(undefined)되어 이후 `await baseAPI.someMethod()` 호출
코드가 계속 실행되어 TypeError를 일으킬 수 있으므로, 401 처리 분기(인터셉터 코드에서 `window.location.href =
...` 직후)에 단순 return 대신 절대 settle되지 않는 Promise를 반환하도록 바꿔 인터셉터가 후속 코드로 이어지지 않게
하세요; 예시로 해당 분기에서 `return new Promise(() => {})`를 반환하도록 변경하여 `errorResponse`를
throw 하거나 undefined를 반환해 후속 코드가 실행되는 상황을 모두 방지하세요 (참조 심볼: axios 응답 인터셉터,
errorResponse, baseAPI.someMethod()).

@Chiman2937 Chiman2937 merged commit 25e35ad into main Feb 20, 2026
9 checks passed
@Chiman2937 Chiman2937 deleted the chiyoung-refactor/axios branch February 20, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant