localhost-back/src/main/java/io/company/localhost/common/exception/GlobalExceptionHandler.java

54 lines
2.0 KiB
Java

/************************************************************
*
* @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<Object> handleCustomException(RestApiException e) {
ErrorCode errorCode = e.getErrorCode();
return ErrorResult.handleExceptionInternal(errorCode);
}
@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<Object> handleIllegalArgument(IllegalArgumentException e) {
log.warn("handleIllegalArgument", e);
ErrorCode errorCode = CommonErrorCode.INVALID_PARAMETER;
return ErrorResult.handleExceptionInternal(errorCode, e.getMessage());
}
@ExceptionHandler({Exception.class})
public ResponseEntity<Object> handleAllException(Exception ex) {
log.warn("handleAllException", ex);
ErrorCode errorCode = CommonErrorCode.INTERNAL_SERVER_ERROR;
return ErrorResult.handleExceptionInternal(errorCode);
}
}