1212import org .springframework .web .bind .annotation .ExceptionHandler ;
1313import org .springframework .web .bind .annotation .RestControllerAdvice ;
1414import org .springframework .web .method .annotation .HandlerMethodValidationException ;
15+ import org .springframework .web .method .annotation .MethodArgumentTypeMismatchException ;
1516
1617import java .util .Map ;
1718import java .util .Objects ;
@@ -24,48 +25,49 @@ public class GeneralExceptionHandler {
2425 @ ExceptionHandler (GeneralException .class )
2526 protected ResponseEntity <ErrorResponse <Void >> handleGeneralException (GeneralException ex ) {
2627 log .warn ("[WARNING] {} : {}" , ex .getClass (), ex .getMessage ());
27- ErrorCode errorCode = ex .getErrorCode ();
28- return ErrorResponse .handle (errorCode );
28+ return ErrorResponse .handle (ex .getErrorCode ());
2929 }
3030
3131 // 요청 파라미터 검증 실패(MethodArgumentNotValidException) 처리 메서드
3232 @ ExceptionHandler (MethodArgumentNotValidException .class )
3333 protected ResponseEntity <ErrorResponse <Map <String , String >>> handleMethodArgumentNotValidException (MethodArgumentNotValidException ex ) {
3434 log .warn ("[WARNING] {} : {}" , ex .getClass (), ex .getMessage ());
35- ErrorCode errorCode = ErrorCode .VALIDATION_FAILED ;
36- return ErrorResponse .handle (errorCode , ex .getFieldErrors ());
35+ return ErrorResponse .handle (ErrorCode .VALIDATION_FAILED , ex .getFieldErrors ());
3736 }
3837
3938 // 데이터 무결성 위반(DataIntegrityViolationException) 처리 메서드
4039 @ ExceptionHandler (DataIntegrityViolationException .class )
4140 protected ResponseEntity <ErrorResponse <Void >> handleDataIntegrityViolationException (DataIntegrityViolationException ex ) {
4241 log .warn ("[WARNING] {} : {}" , ex .getClass (), ex .getMessage ());
43- ErrorCode errorCode = ErrorCode .VALIDATION_FAILED ;
44- return ErrorResponse .handle (errorCode );
42+ return ErrorResponse .handle (ErrorCode .VALIDATION_FAILED );
4543 }
4644
4745 // 컨트롤러 메서드 파라미터의 유효성 검증 실패(HandlerMethodValidationException) 처리 메서드 - @PermissionCheckValidator
4846 @ ExceptionHandler (HandlerMethodValidationException .class )
4947 protected ResponseEntity <ErrorResponse <Void >> handleHandlerMethodValidationException (HandlerMethodValidationException ex ) {
5048 log .warn ("[WARNING] {} : {}" , ex .getClass (), ex .getMessage ());
51- ErrorCode errorCode = extractErrorCode (ex );
52- return ErrorResponse .handle (errorCode );
49+ return ErrorResponse .handle (extractErrorCode (ex ));
5350 }
5451
5552 // 지원되지 않는 HTTP 메서드 요청(HttpRequestMethodNotSupportedException) 처리 메서드
5653 @ ExceptionHandler (HttpRequestMethodNotSupportedException .class )
5754 protected ResponseEntity <ErrorResponse <Void >> handleHttpRequestMethodNotSupportedException (HttpRequestMethodNotSupportedException ex ) {
5855 log .warn ("[WARNING] {} : {}" , ex .getClass (), ex .getMessage ());
59- ErrorCode errorCode = ErrorCode .METHOD_NOT_ALLOWED ;
60- return ErrorResponse .handle (errorCode );
56+ return ErrorResponse .handle (ErrorCode .METHOD_NOT_ALLOWED );
57+ }
58+
59+ // 메서드 인자 타입 불일치(MethodArgumentTypeMismatchException) 처리 메서드
60+ @ ExceptionHandler (MethodArgumentTypeMismatchException .class )
61+ protected ResponseEntity <ErrorResponse <Void >> handleMethodArgumentTypeMismatchException (MethodArgumentTypeMismatchException ex ) {
62+ log .warn ("[WARNING] {} : {}" , ex .getClass (), ex .getMessage ());
63+ return ErrorResponse .handle (ErrorCode .INVALID_ENUM_VALUE );
6164 }
6265
6366 // 기타 모든 예외(Exception) 처리 메서드
6467 @ ExceptionHandler (Exception .class )
6568 protected ResponseEntity <ErrorResponse <Void >> handleException (Exception ex ) {
6669 log .error ("[ERROR] {} : {}" , ex .getClass (), ex .getMessage (), ex );
67- ErrorCode errorCode = ErrorCode .INTERNAL_SERVER_ERROR ;
68- return ErrorResponse .handle (errorCode );
70+ return ErrorResponse .handle (ErrorCode .INTERNAL_SERVER_ERROR );
6971 }
7072
7173 // HandlerMethodValidationException 에서 ErrorCode 를 추출하는 메서드
0 commit comments