fix: QcastException advice 추가

- QcastException 에 메세지 유무에 따라 응답 분기 처리
This commit is contained in:
yoosangwook 2024-10-25 13:26:33 +09:00
parent fc194f2ff1
commit 1812a803b1

View File

@ -3,11 +3,11 @@ package com.interplug.qcast.config.Exception;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@ControllerAdvice
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
protected ResponseEntity<ErrorResponse> handle(HttpRequestMethodNotSupportedException e) {
@ -22,6 +22,16 @@ public class GlobalExceptionHandler {
.body(ErrorResponse.of(errorCode.getMessage()));
}
@ExceptionHandler(QcastException.class)
protected ResponseEntity<ErrorResponse> handle(QcastException e) {
final ErrorCode errorCode = e.getErrorCode();
if (e.getMessage() == null) {
return ResponseEntity.status(errorCode.getStatus())
.body(ErrorResponse.of(errorCode.getMessage()));
}
return ResponseEntity.status(errorCode.getStatus()).body(ErrorResponse.of(e.getMessage()));
}
@ExceptionHandler(Exception.class)
protected ResponseEntity<ErrorResponse> handle(Exception e) {
return ResponseEntity.internalServerError()