55import io .f1 .backend .global .exception .errorcode .ErrorCode ;
66import io .f1 .backend .global .exception .response .ErrorResponse ;
77
8+ import lombok .extern .slf4j .Slf4j ;
89import org .springframework .http .ResponseEntity ;
10+ import org .springframework .http .converter .HttpMessageNotReadableException ;
911import org .springframework .validation .FieldError ;
1012import org .springframework .web .bind .MethodArgumentNotValidException ;
1113import org .springframework .web .bind .annotation .ExceptionHandler ;
1214import org .springframework .web .bind .annotation .RestControllerAdvice ;
1315
16+ @ Slf4j
1417@ RestControllerAdvice
1518public class GlobalExceptionHandler {
1619
1720 @ ExceptionHandler (CustomException .class )
1821 public ResponseEntity <ErrorResponse > handleCustomException (CustomException e ) {
22+ log .warn (e .getMessage ());
1923 ErrorCode errorCode = e .getErrorCode ();
2024
2125 ErrorResponse response = new ErrorResponse (errorCode .getCode (), errorCode .getMessage ());
@@ -24,6 +28,7 @@ public ResponseEntity<ErrorResponse> handleCustomException(CustomException e) {
2428
2529 @ ExceptionHandler (Exception .class )
2630 public ResponseEntity <ErrorResponse > handleException (Exception e ) {
31+ log .warn ("handleException: {}" , e .getMessage ());
2732 CommonErrorCode errorCode = CommonErrorCode .INTERNAL_SERVER_ERROR ;
2833
2934 ErrorResponse response = new ErrorResponse (errorCode .getCode (), errorCode .getMessage ());
@@ -33,7 +38,7 @@ public ResponseEntity<ErrorResponse> handleException(Exception e) {
3338 @ ExceptionHandler (MethodArgumentNotValidException .class )
3439 public ResponseEntity <ErrorResponse > handleMethodArgumentNotValidException (
3540 MethodArgumentNotValidException e ) {
36-
41+ log . warn ( "MethodArgumentNotValidException: {}" , e . getMessage ());
3742 CommonErrorCode code = CommonErrorCode .BAD_REQUEST_DATA ;
3843
3944 String message =
@@ -46,4 +51,14 @@ public ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(
4651
4752 return new ResponseEntity <>(response , code .getHttpStatus ());
4853 }
54+
55+ @ ExceptionHandler (HttpMessageNotReadableException .class )
56+ public ResponseEntity <ErrorResponse > handleHttpMessageNotReadableException (HttpMessageNotReadableException e ) {
57+ log .warn ("HttpMessageNotReadableException: {}" , e .getMessage ());
58+ CommonErrorCode code = CommonErrorCode .INVALID_JSON_FORMAT ;
59+
60+ ErrorResponse response = new ErrorResponse (code .getCode (), code .getMessage ());
61+
62+ return new ResponseEntity <>(response , code .getHttpStatus ());
63+ }
4964}
0 commit comments