HttpMediaTypeNotAcceptableException 에러발생

This commit is contained in:
ysCha 2026-03-19 08:41:03 +09:00
parent 3355561982
commit 50d8a9e3b9

View File

@ -1,6 +1,7 @@
package com.interplug.qcast.config.Exception; package com.interplug.qcast.config.Exception;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
@ -12,6 +13,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(HttpRequestMethodNotSupportedException.class) @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
protected ResponseEntity<ErrorResponse> handle(HttpRequestMethodNotSupportedException e) { protected ResponseEntity<ErrorResponse> handle(HttpRequestMethodNotSupportedException e) {
return ResponseEntity.badRequest() return ResponseEntity.badRequest()
.contentType(MediaType.APPLICATION_JSON)
.body(ErrorResponse.of(ErrorCode.METHOD_NOT_ALLOWED.getMessage())); .body(ErrorResponse.of(ErrorCode.METHOD_NOT_ALLOWED.getMessage()));
} }
@ -19,6 +21,7 @@ public class GlobalExceptionHandler {
protected ResponseEntity<ErrorResponse> handle(BaseException e) { protected ResponseEntity<ErrorResponse> handle(BaseException e) {
final ErrorCode errorCode = e.getErrorCode(); final ErrorCode errorCode = e.getErrorCode();
return ResponseEntity.status(errorCode.getStatus()) return ResponseEntity.status(errorCode.getStatus())
.contentType(MediaType.APPLICATION_JSON)
.body(ErrorResponse.of(errorCode.getMessage())); .body(ErrorResponse.of(errorCode.getMessage()));
} }
@ -27,14 +30,18 @@ public class GlobalExceptionHandler {
final ErrorCode errorCode = e.getErrorCode(); final ErrorCode errorCode = e.getErrorCode();
if (e.getMessage() == null) { if (e.getMessage() == null) {
return ResponseEntity.status(errorCode.getStatus()) return ResponseEntity.status(errorCode.getStatus())
.contentType(MediaType.APPLICATION_JSON)
.body(ErrorResponse.of(errorCode.getMessage())); .body(ErrorResponse.of(errorCode.getMessage()));
} }
return ResponseEntity.status(errorCode.getStatus()).body(ErrorResponse.of(e.getMessage())); return ResponseEntity.status(errorCode.getStatus())
.contentType(MediaType.APPLICATION_JSON)
.body(ErrorResponse.of(e.getMessage()));
} }
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
protected ResponseEntity<ErrorResponse> handle(Exception e) { protected ResponseEntity<ErrorResponse> handle(Exception e) {
return ResponseEntity.internalServerError() return ResponseEntity.internalServerError()
.contentType(MediaType.APPLICATION_JSON)
.body(ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR.getMessage())); .body(ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR.getMessage()));
} }
} }