/************************************************************ * * @packageName : io.company.localhost.common.exception * @fileName : GlobalExceptionHandler.java * @author : 조인제 * @date : 24.12.06 * @description : * * =========================================================== * DATE AUTHOR NOTE * ----------------------------------------------------------- * 24.12.06 조인제 최초 생성 * *************************************************************/ package io.company.localhost.common.exception; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import io.company.localhost.common.exception.code.CommonErrorCode; import io.company.localhost.common.exception.code.ErrorCode; import lombok.extern.slf4j.Slf4j; @Slf4j @RestControllerAdvice(annotations = RestController.class) public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { @ExceptionHandler(RestApiException.class) public ResponseEntity handleCustomException(RestApiException e) { ErrorCode errorCode = e.getErrorCode(); return ErrorResult.handleExceptionInternal(errorCode); } @ExceptionHandler(IllegalArgumentException.class) public ResponseEntity handleIllegalArgument(IllegalArgumentException e) { log.warn("handleIllegalArgument", e); ErrorCode errorCode = CommonErrorCode.INVALID_PARAMETER; return ErrorResult.handleExceptionInternal(errorCode, e.getMessage()); } @ExceptionHandler({Exception.class}) public ResponseEntity handleAllException(Exception ex) { log.warn("handleAllException", ex); ErrorCode errorCode = CommonErrorCode.INTERNAL_SERVER_ERROR; return ErrorResult.handleExceptionInternal(errorCode); } }