From 1812a803b159b19aaae16649b47b6063460e59c6 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Fri, 25 Oct 2024 13:26:33 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20QcastException=20advice=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - QcastException 에 메세지 유무에 따라 응답 분기 처리 --- .../config/Exception/GlobalExceptionHandler.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/interplug/qcast/config/Exception/GlobalExceptionHandler.java b/src/main/java/com/interplug/qcast/config/Exception/GlobalExceptionHandler.java index 8ae4d369..3d556324 100644 --- a/src/main/java/com/interplug/qcast/config/Exception/GlobalExceptionHandler.java +++ b/src/main/java/com/interplug/qcast/config/Exception/GlobalExceptionHandler.java @@ -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 handle(HttpRequestMethodNotSupportedException e) { @@ -22,6 +22,16 @@ public class GlobalExceptionHandler { .body(ErrorResponse.of(errorCode.getMessage())); } + @ExceptionHandler(QcastException.class) + protected ResponseEntity 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 handle(Exception e) { return ResponseEntity.internalServerError()