11package com .back .global .error .handler ;
22
3+ import org .springframework .http .MediaType ;
34import org .springframework .http .ResponseEntity ;
45import org .springframework .http .converter .HttpMessageNotReadableException ;
56import org .springframework .web .HttpRequestMethodNotSupportedException ;
2122@ RestControllerAdvice
2223@ Slf4j
2324public class GlobalExceptionHandler {
25+
2426 // 커스텀 예외 처리
2527 @ ExceptionHandler (ErrorException .class )
2628 protected ResponseEntity <ApiResponse <?>> handleCustomException (ErrorException ex ) {
@@ -35,6 +37,7 @@ protected ResponseEntity<ApiResponse<?>> handleCustomException(ErrorException ex
3537
3638 return ResponseEntity
3739 .status (code .getHttpStatus ())
40+ .contentType (MediaType .APPLICATION_JSON )
3841 .body (ApiResponse .fail (code .getHttpStatus (), ex .getMessage ()));
3942 }
4043
@@ -56,6 +59,7 @@ public ResponseEntity<ApiResponse<?>> handleMethodArgumentNotValid(MethodArgumen
5659
5760 return ResponseEntity
5861 .status (code .getHttpStatus ())
62+ .contentType (MediaType .APPLICATION_JSON )
5963 .body (ApiResponse .fail (code .getHttpStatus (), message ));
6064 }
6165
@@ -67,6 +71,7 @@ public ResponseEntity<ApiResponse<?>> handleJsonProcessing(JsonProcessingExcepti
6771
6872 return ResponseEntity
6973 .status (code .getHttpStatus ())
74+ .contentType (MediaType .APPLICATION_JSON )
7075 .body (ApiResponse .fail (code ));
7176 }
7277
@@ -78,6 +83,7 @@ public ResponseEntity<ApiResponse<?>> handleConstraintViolation(ConstraintViolat
7883
7984 return ResponseEntity
8085 .status (code .getHttpStatus ())
86+ .contentType (MediaType .APPLICATION_JSON )
8187 .body (ApiResponse .fail (code ));
8288 }
8389
@@ -89,6 +95,7 @@ public ResponseEntity<ApiResponse<?>> handleNotReadable(HttpMessageNotReadableEx
8995
9096 return ResponseEntity
9197 .status (code .getHttpStatus ())
98+ .contentType (MediaType .APPLICATION_JSON )
9299 .body (ApiResponse .fail (code ));
93100 }
94101
@@ -100,6 +107,7 @@ public ResponseEntity<ApiResponse<?>> handleTypeMismatch(MethodArgumentTypeMisma
100107
101108 return ResponseEntity
102109 .status (code .getHttpStatus ())
110+ .contentType (MediaType .APPLICATION_JSON )
103111 .body (ApiResponse .fail (code ));
104112 }
105113
@@ -122,6 +130,7 @@ public ResponseEntity<ApiResponse<?>> handleMethodNotSupported(HttpRequestMethod
122130
123131 return ResponseEntity
124132 .status (code .getHttpStatus ())
133+ .contentType (MediaType .APPLICATION_JSON )
125134 .body (ApiResponse .fail (code ));
126135 }
127136
@@ -133,6 +142,7 @@ public ResponseEntity<ApiResponse<?>> handleIllegalArgument(IllegalArgumentExcep
133142
134143 return ResponseEntity
135144 .status (code .getHttpStatus ())
145+ .contentType (MediaType .APPLICATION_JSON )
136146 .body (ApiResponse .fail (code .getHttpStatus (), ex .getMessage ()));
137147 }
138148
@@ -144,6 +154,7 @@ public ResponseEntity<ApiResponse<?>> handleAllException(final Exception ex) {
144154
145155 return ResponseEntity
146156 .status (code .getHttpStatus ())
157+ .contentType (MediaType .APPLICATION_JSON )
147158 .body (ApiResponse .fail (code ));
148159 }
149160}
0 commit comments