Skip to content

fix: 클라이언트 요청 오류를 500 대신 알맞은 4xx로 응답한다 - #144

Merged
ff1451 merged 2 commits into
mainfrom
fix/error-responses
Oct 16, 2026
Merged

ff1451 merged 2 commits into
mainfrom
fix/error-responses

Conversation

@ff1451

@ff1451 ff1451 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

#141(테스트 인프라) 위에 쌓인 PR이다. #141이 머지되면 base가 main으로 바뀐다.

요약

GlobalExceptionHandler가 처리하지 않는 Spring MVC 예외가 모두 마지막 Exception 처리기로 떨어져, 클라이언트가 잘못 보낸 요청이 500 + ERROR 스택 로그가 됐다. 예: GET /v1/admin/images에 purpose를 빼면 500.

변경 (응답 본문 {message} 형식은 그대로)

요청 이전 이후
지원하지 않는 HTTP 메서드 500 405
지원하지 않는 Content-Type 500 415
필수 쿼리 파라미터 누락 500 400 필수 요청 파라미터 'purpose'가 없습니다.
숫자가 아닌 경로 id, 없는 enum 값 500 400 'buildId'의 형식이 올바르지 않습니다.
없는 필드로 sort 500 400
그 밖에 Spring이 4xx로 분류하는 예외(헤더 누락, 406 등) 500 해당 4xx
  • 마지막 처리기에서 Spring의 ErrorResponse를 구현한 예외가 4xx 상태를 갖고 있으면 그 상태로 응답하고 WARN으로 남긴다. 진짜 서버 오류만 500·ERROR로 남는다.
  • BcsdException.getMessage()가 예외 타입 메시지를 돌려준다. 생성자가 메시지를 넘기지 않아 모든 도메인 예외 로그가 message=null이었다.
  • DB 제약 위반(400) 매핑은 바꾸지 않았다.

테스트

  • ClientErrorStatusIntegrationTest(405, 415, 형식 오류 id, 필수 파라미터 누락), AdminImageIntegrationTest에 3건(purpose 누락, 없는 purpose 값, 없는 정렬 필드), BcsdExceptionTest.
    • 수정 전 코드로 돌리면 새 통합 테스트 7건이 모두 500으로 실패함을 확인했다.
  • 로컬 전체 ./gradlew test: 540건 중 539 통과, 1 스킵.

- 405·415·406·헤더 누락 등 Spring MVC 예외는 자신의 4xx 상태로 응답한다(이전에는 전부 500과 ERROR 로그).
- 필수 쿼리 파라미터 누락은 파라미터 이름을 담아 400, 경로·쿼리 값 형식 오류(숫자 아닌 id, 없는 enum 값)와
  없는 필드로의 정렬도 400으로 응답한다.
- 도메인 예외의 getMessage()가 예외 타입 메시지를 돌려줘, 로그에 message=null이 남던 문제를 고친다.
- 응답 본문 형식({message})은 그대로다.
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 32 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 822c9222-0ce1-4a94-a3a0-276790b04b01
📥 Commits

Reviewing files that changed from the base of the PR and between 40063c7 and 7b2a0de.

📒 Files selected for processing: 5
  • src/main/java/com/bcsdlab/bcsdinternalapiv2/global/exception/BcsdException.java
  • src/main/java/com/bcsdlab/bcsdinternalapiv2/global/exception/GlobalExceptionHandler.java
  • src/test/java/com/bcsdlab/bcsdinternalapiv2/global/BcsdExceptionTest.java
  • src/test/java/com/bcsdlab/bcsdinternalapiv2/global/ClientErrorStatusIntegrationTest.java
  • src/test/java/com/bcsdlab/bcsdinternalapiv2/media/AdminImageIntegrationTest.java
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@ff1451
ff1451 merged commit bba378e into main Oct 16, 2026
2 checks passed
@ff1451
ff1451 deleted the fix/error-responses branch October 16, 2026 07:47
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