[REFACTOR] 공통 API 오류 응답 코드 체계를 도입 - #610
Merged
Merged
Conversation
GiJungPark
marked this pull request as ready for review
August 21, 2026 04:10
GiJungPark
marked this pull request as draft
August 21, 2026 06:01
GiJungPark
marked this pull request as ready for review
August 24, 2026 09:23
ljy1348
reviewed
Aug 25, 2026
| public ResponseEntity<ErrorResult> HttpRequestMethodNotSupportedExceptionHandler( | ||
| HttpRequestMethodNotSupportedException e) { | ||
| log.warn("[HttpRequestMethodNotSupportedException] exception ", e); | ||
| return errorResponse(METHOD_NOT_SUPPORTED); |
Contributor
There was a problem hiding this comment.
p2 현재 코드는 다음처럼 예외에서 상태와 본문만 새로 만듭니다.
HttpRequestMethodNotSupportedException에는 Spring이 지원 가능한 HTTP 메서드를 e.getHeaders()의 Allow 헤더로 담아 둡니다. 하지만 현재 errorResponse()는 이 헤더를 전달받지 않으므로 버려집니다.
405 응답은 HTTP 규격상 Allow 헤더를 반드시 포함해야 합니다. 따라서 단순 부가정보 누락이 아니라 HTTP 계약 위반입니다.
권장 수정:
return errorResponse(METHOD_NOT_SUPPORTED, e.getHeaders());
그리고 errorResponse()에 헤더를 받는 오버로드를 추가해야 합니다.
private ResponseEntity errorResponse(
ICustomError error,
HttpHeaders headers
) {
return ResponseEntity
.status(error.getStatusCode())
.headers(headers)
.contentType(APPLICATION_JSON)
.body(new ErrorResult(error.getCode(), error.getDescription()));
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Key Changes
COMMON-001,COMMON-002로 분리하고 기존 검증 메시지·HTTP 상태·도메인 오류 계약을 유지했습니다. (5d278588)COMMON-003~014를 부여했습니다. 예상하지 못한 예외는 내부 내용을 노출하지 않는COMMON-999로 응답합니다. (7af902c3)AUTH-001로 바뀌지 않도록 명시적인 예외 매핑과 catch-all을 추가했습니다.AccessDeniedException은 Security로 다시 전달해 기존 401/403 판단을 보존하고, 일반 403은COMMON-012본문을 반환합니다. (7af902c3)AUTH-*와 도메인 오류 회귀를 검증했습니다. REST Docs named example도 새 공통 코드로 갱신했습니다. (7af902c3)7c85e7ff,8b3c1953)To Reviewers
BAD_REQUEST·CONFLICT문자열을ErrorResult.code로 사용하는 소스 경로는 제거했습니다. 클라이언트가 해당 문자열로 분기했다면COMMON-*전환이 필요합니다./error인가 정책은 변경하지 않았습니다. 인증 토큰 오류는 기존AUTH-*, 도메인 인가 오류는 기존 도메인 코드를 유지합니다.COMMON-999는 고정 메시지만 응답하고 원본 예외·SQL·스택 트레이스는 로그에만 남깁니다../gradlew build -x test, 관련 테스트,./gradlew clean apiDocs는 성공했습니다. 전체./gradlew test는 761개 중 12개가 실패하며, 변경 전 사본에서도 동일하게 재현된 로컬 MySQL 시드·Redis 상태 관련 기존 환경 실패입니다.References