From 5ae9a3f7b7a555dce16af912ec7fc1dc2986d20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Fri, 8 Nov 2024 09:26:39 +0900 Subject: [PATCH] fix: error handling with status code --- .../core/exception/album/AlbumCustomException.java | 1 - .../core/exception/common/GlobalExceptionHandler.java | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/pocket/core/exception/album/AlbumCustomException.java b/core/src/main/java/com/pocket/core/exception/album/AlbumCustomException.java index 91d79a6..0accd2d 100644 --- a/core/src/main/java/com/pocket/core/exception/album/AlbumCustomException.java +++ b/core/src/main/java/com/pocket/core/exception/album/AlbumCustomException.java @@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.ResponseStatus; @Getter -@ResponseStatus(HttpStatus.BAD_REQUEST) public class AlbumCustomException extends RuntimeException { private final BaseErrorCode errorCode; diff --git a/core/src/main/java/com/pocket/core/exception/common/GlobalExceptionHandler.java b/core/src/main/java/com/pocket/core/exception/common/GlobalExceptionHandler.java index 82f3cf4..cd3ea2c 100644 --- a/core/src/main/java/com/pocket/core/exception/common/GlobalExceptionHandler.java +++ b/core/src/main/java/com/pocket/core/exception/common/GlobalExceptionHandler.java @@ -1,5 +1,6 @@ package com.pocket.core.exception.common; +import com.pocket.core.exception.album.AlbumCustomException; import com.pocket.core.exception.jwt.SecurityCustomException; import com.pocket.core.exception.photobooth.PhotoBoothCustomException; import org.springframework.http.HttpStatus; @@ -28,4 +29,12 @@ public ResponseEntity> handleSecurityException(Secur return new ResponseEntity<>(response, ex.getErrorCode().getHttpStatus()); } + @ExceptionHandler(AlbumCustomException.class) + public ResponseEntity> handleAlbumCustomException(AlbumCustomException ex) { + ApplicationResponse response = new ApplicationResponse<>( + new ApplicationResult(Integer.parseInt(ex.getErrorCode().getCode()), ex.getErrorCode().getMessage()), + null + ); + return new ResponseEntity<>(response, ex.getErrorCode().getHttpStatus()); + } }