From 62c5fb528e30d0d6fb7f45ab8b0962b0bacae26b Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Fri, 27 Oct 2023 16:38:04 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Global=20Exception=20=ED=95=B8=EB=93=A4?= =?UTF-8?q?=EB=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/GlobalControllerAdvice.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/fc/toy_project2/global/exception/GlobalControllerAdvice.java diff --git a/src/main/java/com/fc/toy_project2/global/exception/GlobalControllerAdvice.java b/src/main/java/com/fc/toy_project2/global/exception/GlobalControllerAdvice.java new file mode 100644 index 0000000..b99775c --- /dev/null +++ b/src/main/java/com/fc/toy_project2/global/exception/GlobalControllerAdvice.java @@ -0,0 +1,20 @@ +package com.fc.toy_project2.global.exception; + +import com.fc.toy_project2.global.DTO.ResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.BindException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GlobalControllerAdvice { + + @ExceptionHandler + public ResponseEntity> bindException(BindException e) { + return ResponseEntity + .status(HttpStatus.BAD_REQUEST) + .body(ResponseDTO.res(HttpStatus.BAD_REQUEST, + e.getBindingResult().getAllErrors().get(0).getDefaultMessage())); + } +}