[REFACTOR] 코드 일관성 개선#11
Conversation
개요CustomErrorAttributes 컴포넌트를 제거하고 GlobalExceptionHandler의 예외 핸들러들을 일관된 명명 규칙으로 리팩토링했으며, NotificationController의 응답 메시지를 더 구체적인 한국어 표현으로 업데이트하고, 이에 맞춰 통합 테스트와 단위 테스트의 어설션을 수정했습니다. 변경사항예외 처리 정제 및 알림 API 메시지 개선
코드 리뷰 예상 시간🎯 2 (단순) | ⏱️ ~12분 관련 PR
추천 리뷰어
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@src/main/java/com/example/auctionnotification/common/exception/GlobalExceptionHandler.java`:
- Line 63: The handler for HttpRequestMethodNotSupportedException in
GlobalExceptionHandler is returning HttpStatus.BAD_REQUEST; change it to return
HttpStatus.METHOD_NOT_ALLOWED instead so the response status conforms to RFC
7231 and Spring conventions—locate the return statement that builds the
ResponseEntity (the line using
ResponseEntity.status(HttpStatus.BAD_REQUEST).body(BaseResponse.fail(...))) and
replace HttpStatus.BAD_REQUEST with HttpStatus.METHOD_NOT_ALLOWED while keeping
the existing body payload and message intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f909c666-c45c-426e-a757-0714ea2c8c43
📒 Files selected for processing (5)
src/main/java/com/example/auctionnotification/common/exception/CustomErrorAttributes.javasrc/main/java/com/example/auctionnotification/common/exception/GlobalExceptionHandler.javasrc/main/java/com/example/auctionnotification/notification/controller/NotificationController.javasrc/test/java/com/example/auctionnotification/notification/NotificationIntegrationTest.javasrc/test/java/com/example/auctionnotification/notification/controller/NotificationControllerTest.java
💤 Files with no reviewable changes (1)
- src/main/java/com/example/auctionnotification/common/exception/CustomErrorAttributes.java
| public ResponseEntity<BaseResponse<Void>> handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { | ||
| log.error("지원하지 않는 메소드 에러 발생 : ", e); | ||
| return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(BaseResponse.fail(HttpStatus.METHOD_NOT_ALLOWED.name(), "지원하지 않는 HTTP 메소드입니다")); | ||
| return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(BaseResponse.fail(HttpStatus.BAD_REQUEST.name(), "지원하지 않는 HTTP 메소드입니다")); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# HttpRequestMethodNotSupportedException이 발생하는 컨텍스트 확인
rg -n -C3 --type=java "HttpRequestMethodNotSupportedException"Repository: GigaMak2/auction-notification
Length of output: 2461
🏁 Script executed:
# Check if there are any tests for this exception handler
fd -e java -e groovy -e xml | xargs grep -l "HttpRequestMethodNotSupportedException\|handleHttpRequestMethodNotSupportedException" 2>/dev/null | head -20Repository: GigaMak2/auction-notification
Length of output: 164
🏁 Script executed:
# Check what status code Spring uses by default for this exception
rg -n "METHOD_NOT_ALLOWED" --type=java | head -20Repository: GigaMak2/auction-notification
Length of output: 55
🏁 Script executed:
# Look for other exception handlers to understand the pattern
rg -B2 -A5 "@ExceptionHandler" --type=java src/main/java/com/example/auctionnotification/common/exception/ 2>/dev/nullRepository: GigaMak2/auction-notification
Length of output: 8642
🌐 Web query:
Spring HttpRequestMethodNotSupportedException default HTTP status code RFC 7231
💡 Result:
Spring HttpRequestMethodNotSupportedException default HTTP status code: 405 (Method Not Allowed) [1][2]. How this relates to RFC 7231: - RFC 7231 specifies that if a server receives a request method that is known but not allowed for the target resource, it SHOULD respond with 405 (Method Not Allowed) [2]. Spring details: - In Spring Framework, HttpRequestMethodNotSupportedException implements ErrorResponse and its getStatusCode returns HttpStatus.METHOD_NOT_ALLOWED (405) [1][3].
Citations:
- 1: https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java
- 2: https://datatracker.ietf.org/doc/html/rfc7231
- 3: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/HttpRequestMethodNotSupportedException.html
HTTP 상태 코드가 HTTP 표준 및 Spring Framework 설계에 맞지 않습니다.
HttpRequestMethodNotSupportedException의 응답 상태 코드를 400(Bad Request)에서 405(Method Not Allowed)로 변경해야 합니다.
문제점:
- Spring Framework의
HttpRequestMethodNotSupportedException은 기본적으로 405 상태 코드를 반환하도록 설계되었습니다 - RFC 7231에서는 리소스가 해당 HTTP 메서드를 지원하지 않을 때 405 Method Not Allowed를 사용하도록 명시합니다
- 현재 사용 중인 400 Bad Request는 요청 구문이 잘못되었을 때 사용되는 상태 코드입니다
- 이 변경사항은 API 계약을 변경하여 405 상태 코드에 의존하는 클라이언트의 오류 처리 로직을 깨뜨립니다
제안하는 수정
- return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(BaseResponse.fail(HttpStatus.BAD_REQUEST.name(), "지원하지 않는 HTTP 메소드입니다"));
+ return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(BaseResponse.fail(HttpStatus.METHOD_NOT_ALLOWED.name(), "지원하지 않는 HTTP 메소드입니다"));📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(BaseResponse.fail(HttpStatus.BAD_REQUEST.name(), "지원하지 않는 HTTP 메소드입니다")); | |
| return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(BaseResponse.fail(HttpStatus.METHOD_NOT_ALLOWED.name(), "지원하지 않는 HTTP 메소드입니다")); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/main/java/com/example/auctionnotification/common/exception/GlobalExceptionHandler.java`
at line 63, The handler for HttpRequestMethodNotSupportedException in
GlobalExceptionHandler is returning HttpStatus.BAD_REQUEST; change it to return
HttpStatus.METHOD_NOT_ALLOWED instead so the response status conforms to RFC
7231 and Spring conventions—locate the return statement that builds the
ResponseEntity (the line using
ResponseEntity.status(HttpStatus.BAD_REQUEST).body(BaseResponse.fail(...))) and
replace HttpStatus.BAD_REQUEST with HttpStatus.METHOD_NOT_ALLOWED while keeping
the existing body payload and message intact.
📝 작업 내용
GlobalExceptionHandler
handle접두어 + camelCase로 통일###응답 형식 통일
~했습니다형식으로 통일✅ 체크리스트 (Checklist)
Summary by CodeRabbit