Skip to content

[fix] @Validated 컨트롤러 파라미터 검증 실패 시 500 에러 반환 버그 수정#360

Merged
hd0rable merged 1 commit into
developfrom
fix/constraint-violation-500
Jun 24, 2026
Merged

[fix] @Validated 컨트롤러 파라미터 검증 실패 시 500 에러 반환 버그 수정#360
hd0rable merged 1 commit into
developfrom
fix/constraint-violation-500

Conversation

@hd0rable

@hd0rable hd0rable commented Jun 24, 2026

Copy link
Copy Markdown
Member

#️⃣ 연관된 이슈

closes #이슈번호

📝 작업 내용

이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

문제
Spring Boot 3.x (Spring Framework 6.1+)에서 @validated 컨트롤러의
@PathVariable @pattern 검증 실패 시 HandlerMethodValidationException이 발생하지만
GlobalExceptionHandler에 해당 핸들러가 없어 handleServerErrors(RuntimeException)로
떨어져 500을 반환하던 문제

원인
Spring 6.1+에서 컨트롤러 메서드 파라미터 검증 실패 시
기존 ConstraintViolationException 대신 HandlerMethodValidationException을 던지도록 변경됨
기존 핸들러는 ConstraintViolationException만 처리하고 있었음

--> HandlerMethodValidationException 전용 핸들러 추가 → 400 반환

📸 스크린샷

💬 리뷰 요구사항

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

📌 PR 진행 시 이러한 점들을 참고해 주세요

* P1 : 꼭 반영해 주세요 (Request Changes) - 이슈가 발생하거나 취약점이 발견되는 케이스 등
* P2 : 반영을 적극적으로 고려해 주시면 좋을 것 같아요 (Comment)
* P3 : 이런 방법도 있을 것 같아요~ 등의 사소한 의견입니다 (Chore)

Summary by CodeRabbit

버그 수정

  • 요청 파라미터 검증 실패 시 더 명확하고 일관된 오류 메시지를 제공하도록 개선했습니다. 이제 검증 오류 발생 시 사용자가 더 쉽게 문제를 파악할 수 있습니다.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cd7a0d1e-da8e-4327-9428-de85e298e8d9

📥 Commits

Reviewing files that changed from the base of the PR and between 9e87db0 and 4e99e5b.

📒 Files selected for processing (1)
  • src/main/java/konkuk/thip/common/exception/handler/GlobalExceptionHandler.java

Walkthrough

GlobalExceptionHandlerHandlerMethodValidationException 전용 @ExceptionHandler 메서드를 추가했습니다. beanResultsvalueResults를 병합하여 첫 번째 resolvableErrors의 메시지를 추출하고, API_INVALID_PARAM 상태 코드로 ErrorResponse를 반환합니다. 관련 임포트(HandlerMethodValidationException, Stream)도 함께 추가되었습니다.

Changes

HandlerMethodValidationException 처리 로직 추가

Layer / File(s) Summary
HandlerMethodValidationException 핸들러 및 임포트 추가
src/main/java/konkuk/thip/common/exception/handler/GlobalExceptionHandler.java
HandlerMethodValidationExceptionStream 임포트를 추가하고, beanResults·valueResults 병합 후 첫 번째 resolvableErrors 메시지를 선택하여 API_INVALID_PARAM으로 ErrorResponse를 반환하는 핸들러 메서드를 구현했습니다.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐇 파라미터 검증 실패해도 괜찮아요,
핸들러가 새로 생겨 오류를 잡아요~
beanResults, valueResults 합쳐서 보고,
첫 번째 메시지 골라 응답을 보내고,
API_INVALID_PARAM, 깔끔하게 처리! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경 사항의 핵심을 정확하게 설명합니다. @Validated 컨트롤러 파라미터 검증 실패 시 500 에러 대신 400 에러를 반환하도록 수정하는 것이 주요 변경 사항이며, 제목이 이를 명확하게 반영하고 있습니다.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/constraint-violation-500

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.

@github-actions

Copy link
Copy Markdown

Test Results

488 tests   488 ✅  46s ⏱️
145 suites    0 💤
145 files      0 ❌

Results for commit 4e99e5b.

@hd0rable hd0rable merged commit 1347003 into develop Jun 24, 2026
4 checks passed
@hd0rable hd0rable deleted the fix/constraint-violation-500 branch June 24, 2026 16:02
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