From 7ca8be0dcea21ddd14e48f3a2916abf7b18e444f Mon Sep 17 00:00:00 2001 From: Lim Jonguk Date: Tue, 8 Mar 2022 17:46:57 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Exception=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/handling/CustomErrorAttributes.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/xit/core/exception/handling/CustomErrorAttributes.java b/src/main/java/com/xit/core/exception/handling/CustomErrorAttributes.java index a243e72..ef5628d 100644 --- a/src/main/java/com/xit/core/exception/handling/CustomErrorAttributes.java +++ b/src/main/java/com/xit/core/exception/handling/CustomErrorAttributes.java @@ -1,5 +1,7 @@ package com.xit.core.exception.handling; +import com.xit.core.constant.ErrorCode; +import com.xit.core.exception.CustomBaseException; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.servlet.error.DefaultErrorAttributes; @@ -32,11 +34,21 @@ public class CustomErrorAttributes extends DefaultErrorAttributes { Map result = super.getErrorAttributes(webRequest, options); //result.remove("timestamp"); //result.put("trace", "AAAAAAAAAAAAAAAAAAAAAAA"); - log.error("================================================================================="); + + final Throwable error = super.getError(webRequest); + if(error instanceof CustomBaseException){ + ErrorCode errorCode = ((CustomBaseException) error).getErrorCode(); + result.put("status", errorCode.getHttpStatus()); + result.put("code", errorCode.getHttpStatus().toString()); + result.put("message", errorCode.getMessage()); + } + + log.error("====================== Exception handler 에서 catch하지 못한 에러 :: CustomErrorAttributes 에서 처리 =================================="); log.error("========================== 처리되지 않은 에러 발생 =================================="); log.error("{}", result); log.error("========================== 반드시 처리해 주세요 ====================================="); log.error("=================================================================================="); + return result; //return super.getErrorAttributes(webRequest, options);