From 3fa4555a4b0097b070205c88ebd34b394a8914fd Mon Sep 17 00:00:00 2001 From: Jeong Jiho Date: Wed, 17 Jul 2024 15:59:48 +0900 Subject: [PATCH] =?UTF-8?q?[BE]=20feat:=20=EC=BB=A4=EC=8A=A4=ED=85=80=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EB=8F=84=EC=9E=85=20=EB=B0=8F=20GlobalExc?= =?UTF-8?q?eptionHandler=20=EC=B2=98=EB=A6=AC=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#93)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friendogly/GlobalExceptionHandler.java | 11 +++++++++-- .../friendogly/exception/FriendoglyException.java | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 backend/src/main/java/com/woowacourse/friendogly/exception/FriendoglyException.java diff --git a/backend/src/main/java/com/woowacourse/friendogly/GlobalExceptionHandler.java b/backend/src/main/java/com/woowacourse/friendogly/GlobalExceptionHandler.java index 3cb627ecc..cb81cf01b 100644 --- a/backend/src/main/java/com/woowacourse/friendogly/GlobalExceptionHandler.java +++ b/backend/src/main/java/com/woowacourse/friendogly/GlobalExceptionHandler.java @@ -1,9 +1,11 @@ package com.woowacourse.friendogly; +import com.woowacourse.friendogly.exception.FriendoglyException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.servlet.resource.NoResourceFoundException; @@ -11,11 +13,16 @@ @RestControllerAdvice public class GlobalExceptionHandler { - @ExceptionHandler(IllegalArgumentException.class) - public ResponseEntity handle(RuntimeException exception) { + @ExceptionHandler(FriendoglyException.class) + public ResponseEntity handle(FriendoglyException exception) { return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST); } + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity handle(MethodArgumentNotValidException exception) { + return new ResponseEntity<>("유효하지 않은 요청 값입니다.", HttpStatus.BAD_REQUEST); + } + @ExceptionHandler(HttpMessageNotReadableException.class) public ResponseEntity handle(HttpMessageNotReadableException exception) { return new ResponseEntity<>("읽을 수 없는 HTTP 메세지입니다.", HttpStatus.BAD_REQUEST); diff --git a/backend/src/main/java/com/woowacourse/friendogly/exception/FriendoglyException.java b/backend/src/main/java/com/woowacourse/friendogly/exception/FriendoglyException.java new file mode 100644 index 000000000..60cd06fdd --- /dev/null +++ b/backend/src/main/java/com/woowacourse/friendogly/exception/FriendoglyException.java @@ -0,0 +1,8 @@ +package com.woowacourse.friendogly.exception; + +public class FriendoglyException extends RuntimeException { + + public FriendoglyException(String message) { + super(message); + } +}