From b34d6cea10b6d15087de594275a6b3a61f0ff9f5 Mon Sep 17 00:00:00 2001 From: kyum-q <109158497+kyum-q@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:01:46 +0900 Subject: [PATCH] =?UTF-8?q?fix(exception):=20=EC=8A=A4=ED=94=84=EB=A7=81?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=EC=97=90=20response=20=EB=94=94=ED=85=8C?= =?UTF-8?q?=EC=9D=BC=20=EA=B0=92=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/GlobalExceptionHandler.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/codezap/global/exception/GlobalExceptionHandler.java b/backend/src/main/java/codezap/global/exception/GlobalExceptionHandler.java index 14f0f78a8..0e1416440 100644 --- a/backend/src/main/java/codezap/global/exception/GlobalExceptionHandler.java +++ b/backend/src/main/java/codezap/global/exception/GlobalExceptionHandler.java @@ -24,6 +24,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { private static final String PROPERTY_ERROR_CODE = "errorCode"; private static final String PROPERTY_TIMESTAMP = "timestamp"; + private static final String DEFAULT_DETAIL_MASSAGE = "디테일 값이 존재하지 않습니다."; @ExceptionHandler public ResponseEntity handleCodeZapException(CodeZapException codeZapException) { @@ -63,17 +64,18 @@ public ResponseEntity handleException(Exception exception) { protected ResponseEntity createResponseEntity( @Nullable Object body, HttpHeaders headers, HttpStatusCode statusCode, WebRequest request ) { - ProblemDetail problemDetail = ProblemDetail.forStatus(statusCode); - if (body instanceof Exception) { - problemDetail.setDetail(((Exception) body).getMessage()); + if (body instanceof ProblemDetail) { + return ResponseEntity.status(statusCode) + .body(setProperties((ProblemDetail) body, ErrorCode.SPRING_GLOBAL_EXCEPTION.getCode())); } + ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(statusCode, DEFAULT_DETAIL_MASSAGE); return ResponseEntity.status(statusCode) .body(setProperties(problemDetail, ErrorCode.SPRING_GLOBAL_EXCEPTION.getCode())); } public static ProblemDetail setProperties(ProblemDetail problemDetail, int code) { problemDetail.setProperty(PROPERTY_ERROR_CODE, code); - problemDetail.setProperty(PROPERTY_TIMESTAMP, LocalDateTime.now()); + problemDetail.setProperty(PROPERTY_TIMESTAMP, LocalDateTime.now().toString()); return problemDetail; }