diff --git a/src/main/java/com/example/week2/exception/GlobalExceptionHandler.java b/src/main/java/com/example/week2/exception/GlobalExceptionHandler.java index 91a694e..7b5b5c8 100644 --- a/src/main/java/com/example/week2/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/example/week2/exception/GlobalExceptionHandler.java @@ -1,6 +1,7 @@ package com.example.week2.exception; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -19,4 +20,25 @@ public String handleInternalError() { log.error("InternalError 처리 시작"); return "InternalError 핸들링"; } +/* + @ExceptionHandler(CustomException.class) + public String handleCustomException() { + log.error("커스텀 exception 발생 !!!"); + return "커스텀 예외처리 성공 !!"; + } + */ + @ExceptionHandler(CustomException.class) + public ResponseEntity handleCustomException(CustomException e) { + log.error("CustomException 발생: {}" , e.getMessage(), e); + + ErrorCode errorCode = e.getErrorCode(); + + ErrorResponse response = ErrorResponse.builder() + .errorCode(errorCode) + .errorMessage(errorCode.getMessage()) + .build(); + + return ResponseEntity.status(errorCode.getStatus()).body(response); + } + }