From fe4379b3bedcbf7ab602d7fa52d1eca49ff84126 Mon Sep 17 00:00:00 2001 From: Anna-Jin Date: Tue, 19 Jul 2022 19:08:31 +0900 Subject: [PATCH] =?UTF-8?q?#33=20[Update]=20NullPointerException=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/mpnp/baechelin/exception/ErrorCode.java | 4 +++- .../java/com/mpnp/baechelin/exception/ErrorResponse.java | 2 ++ .../mpnp/baechelin/exception/GlobalExceptionHandler.java | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mpnp/baechelin/exception/ErrorCode.java b/src/main/java/com/mpnp/baechelin/exception/ErrorCode.java index db5e5f8..ea36380 100644 --- a/src/main/java/com/mpnp/baechelin/exception/ErrorCode.java +++ b/src/main/java/com/mpnp/baechelin/exception/ErrorCode.java @@ -19,7 +19,9 @@ public enum ErrorCode { ALREADY_LOGIN_ACCOUNT(400, "E-ALA400","다른 계정으로 로그인 되었습니다."), API_LOAD_FAILURE(500, "E-ALF500", "API 로딩에 실패하였습니다."), - API_NO_RESULT(500, "E-ALF500", "API 결과가 존재하지 않습니다."); + API_NO_RESULT(500, "E-ALF500", "API 결과가 존재하지 않습니다."), + + NULL_POINTER_EXCEPTION(500, "E-NPE500", "NULL값이 들어올 수 없습니다."); private final int status; private final String code; diff --git a/src/main/java/com/mpnp/baechelin/exception/ErrorResponse.java b/src/main/java/com/mpnp/baechelin/exception/ErrorResponse.java index 265af2e..3b50255 100644 --- a/src/main/java/com/mpnp/baechelin/exception/ErrorResponse.java +++ b/src/main/java/com/mpnp/baechelin/exception/ErrorResponse.java @@ -1,7 +1,9 @@ package com.mpnp.baechelin.exception; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import org.springframework.http.ResponseEntity; import java.time.LocalDateTime; diff --git a/src/main/java/com/mpnp/baechelin/exception/GlobalExceptionHandler.java b/src/main/java/com/mpnp/baechelin/exception/GlobalExceptionHandler.java index fd6229d..c5c1cfc 100644 --- a/src/main/java/com/mpnp/baechelin/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/mpnp/baechelin/exception/GlobalExceptionHandler.java @@ -19,6 +19,12 @@ protected ResponseEntity handleCustomException(CustomException e) return ErrorResponse.toResponseEntity(e.getErrorCode()); } + @ExceptionHandler(value = NullPointerException.class) + protected ResponseEntity handleNullPointerException(NullPointerException e) { + log.error("Null값이 들어올 수 없습니다."); + return ErrorResponse.toResponseEntity(ErrorCode.NULL_POINTER_EXCEPTION); + } + @ExceptionHandler(value = SignatureException.class) protected ResponseEntity handleSignatureException(SignatureException e) { log.error("잘못된 JWT 서명입니다.");