12
12
import org .springframework .web .bind .annotation .ExceptionHandler ;
13
13
import org .springframework .web .bind .annotation .RestControllerAdvice ;
14
14
import org .springframework .web .method .annotation .HandlerMethodValidationException ;
15
+ import org .springframework .web .method .annotation .MethodArgumentTypeMismatchException ;
15
16
16
17
import java .util .Map ;
17
18
import java .util .Objects ;
@@ -24,48 +25,49 @@ public class GeneralExceptionHandler {
24
25
@ ExceptionHandler (GeneralException .class )
25
26
protected ResponseEntity <ErrorResponse <Void >> handleGeneralException (GeneralException ex ) {
26
27
log .warn ("[WARNING] {} : {}" , ex .getClass (), ex .getMessage ());
27
- ErrorCode errorCode = ex .getErrorCode ();
28
- return ErrorResponse .handle (errorCode );
28
+ return ErrorResponse .handle (ex .getErrorCode ());
29
29
}
30
30
31
31
// 요청 파라미터 검증 실패(MethodArgumentNotValidException) 처리 메서드
32
32
@ ExceptionHandler (MethodArgumentNotValidException .class )
33
33
protected ResponseEntity <ErrorResponse <Map <String , String >>> handleMethodArgumentNotValidException (MethodArgumentNotValidException ex ) {
34
34
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 ());
37
36
}
38
37
39
38
// 데이터 무결성 위반(DataIntegrityViolationException) 처리 메서드
40
39
@ ExceptionHandler (DataIntegrityViolationException .class )
41
40
protected ResponseEntity <ErrorResponse <Void >> handleDataIntegrityViolationException (DataIntegrityViolationException ex ) {
42
41
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 );
45
43
}
46
44
47
45
// 컨트롤러 메서드 파라미터의 유효성 검증 실패(HandlerMethodValidationException) 처리 메서드 - @PermissionCheckValidator
48
46
@ ExceptionHandler (HandlerMethodValidationException .class )
49
47
protected ResponseEntity <ErrorResponse <Void >> handleHandlerMethodValidationException (HandlerMethodValidationException ex ) {
50
48
log .warn ("[WARNING] {} : {}" , ex .getClass (), ex .getMessage ());
51
- ErrorCode errorCode = extractErrorCode (ex );
52
- return ErrorResponse .handle (errorCode );
49
+ return ErrorResponse .handle (extractErrorCode (ex ));
53
50
}
54
51
55
52
// 지원되지 않는 HTTP 메서드 요청(HttpRequestMethodNotSupportedException) 처리 메서드
56
53
@ ExceptionHandler (HttpRequestMethodNotSupportedException .class )
57
54
protected ResponseEntity <ErrorResponse <Void >> handleHttpRequestMethodNotSupportedException (HttpRequestMethodNotSupportedException ex ) {
58
55
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 );
61
64
}
62
65
63
66
// 기타 모든 예외(Exception) 처리 메서드
64
67
@ ExceptionHandler (Exception .class )
65
68
protected ResponseEntity <ErrorResponse <Void >> handleException (Exception ex ) {
66
69
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 );
69
71
}
70
72
71
73
// HandlerMethodValidationException 에서 ErrorCode 를 추출하는 메서드
0 commit comments