From 7128bbf289b839329023850a5702c46ee43d2071 Mon Sep 17 00:00:00 2001 From: dtd1614 Date: Thu, 16 May 2024 18:12:51 +0900 Subject: [PATCH] =?UTF-8?q?rename:=20=EC=98=88=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...dvice.java => GlobalExceptionHandler.java} | 23 +++++++++++++++---- ...e.java => RestGlobalExceptionHandler.java} | 8 +++---- 2 files changed, 22 insertions(+), 9 deletions(-) rename src/main/java/today/meevote/controllerAdvice/{ControllerAdvice.java => GlobalExceptionHandler.java} (50%) rename src/main/java/today/meevote/controllerAdvice/{RestControllerAdvice.java => RestGlobalExceptionHandler.java} (92%) diff --git a/src/main/java/today/meevote/controllerAdvice/ControllerAdvice.java b/src/main/java/today/meevote/controllerAdvice/GlobalExceptionHandler.java similarity index 50% rename from src/main/java/today/meevote/controllerAdvice/ControllerAdvice.java rename to src/main/java/today/meevote/controllerAdvice/GlobalExceptionHandler.java index 7fc2a39..a1cb845 100644 --- a/src/main/java/today/meevote/controllerAdvice/ControllerAdvice.java +++ b/src/main/java/today/meevote/controllerAdvice/GlobalExceptionHandler.java @@ -1,14 +1,17 @@ package today.meevote.controllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; - import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; import today.meevote.exception.view.UnauthenticatedException; import today.meevote.exception.view.NotFoundException; +import today.meevote.response.BaseResponse; +import today.meevote.response.FailureInfo; -@org.springframework.web.bind.annotation.ControllerAdvice @Slf4j -public class ControllerAdvice { +@ControllerAdvice +public class GlobalExceptionHandler { @ExceptionHandler(UnauthenticatedException.class) public String unauthenticatedException(UnauthenticatedException e){ @@ -21,5 +24,15 @@ public String notFoundException(NotFoundException e) { log.error("notFoundException", e); return "redirect:/notfound"; } - + + + @ExceptionHandler(MethodArgumentNotValidException.class) + protected BaseResponse methodArgumentNotValidException(MethodArgumentNotValidException e){ + log.error("invalidInputException", e); + return new BaseResponse( + false, + FailureInfo.INVALID_INPUT.getCode(), + e.getFieldError().getDefaultMessage() + ); + } } diff --git a/src/main/java/today/meevote/controllerAdvice/RestControllerAdvice.java b/src/main/java/today/meevote/controllerAdvice/RestGlobalExceptionHandler.java similarity index 92% rename from src/main/java/today/meevote/controllerAdvice/RestControllerAdvice.java rename to src/main/java/today/meevote/controllerAdvice/RestGlobalExceptionHandler.java index 913a484..d9f51f2 100644 --- a/src/main/java/today/meevote/controllerAdvice/RestControllerAdvice.java +++ b/src/main/java/today/meevote/controllerAdvice/RestGlobalExceptionHandler.java @@ -5,13 +5,13 @@ import jakarta.validation.ConstraintViolationException; import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RestControllerAdvice; import today.meevote.exception.rest.RestException; import today.meevote.response.BaseResponse; import today.meevote.response.FailureInfo; - -@org.springframework.web.bind.annotation.RestControllerAdvice @Slf4j -public class RestControllerAdvice { +@RestControllerAdvice +public class RestGlobalExceptionHandler { @ExceptionHandler(Exception.class) protected BaseResponse internalSeverException(Exception e){ @@ -38,7 +38,7 @@ protected BaseResponse constraintViolationException(ConstraintViolationException e.getConstraintViolations().stream().toList().get(0).getMessage() ); } - + @ExceptionHandler(RestException.class) protected BaseResponse restException(RestException e){ log.error("restException", e);