diff --git a/src/main/java/org/hankki/hankkiserver/api/advice/GlobalExceptionHandler.java b/src/main/java/org/hankki/hankkiserver/api/advice/GlobalExceptionHandler.java index de47e310..fc1ac00a 100644 --- a/src/main/java/org/hankki/hankkiserver/api/advice/GlobalExceptionHandler.java +++ b/src/main/java/org/hankki/hankkiserver/api/advice/GlobalExceptionHandler.java @@ -6,11 +6,15 @@ import org.hankki.hankkiserver.common.code.StoreErrorCode; import org.hankki.hankkiserver.common.code.StoreImageErrorCode; import org.hankki.hankkiserver.common.exception.*; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.springframework.web.multipart.MaxUploadSizeExceededException; +import org.springframework.web.servlet.resource.NoResourceFoundException; import software.amazon.awssdk.core.exception.SdkClientException; @RestControllerAdvice @@ -19,62 +23,79 @@ public class GlobalExceptionHandler { @ExceptionHandler(BadRequestException.class) public HankkiResponse handleBadRequestException(BadRequestException e) { - log.error("handleBadRequestException() in GlobalExceptionHandler throw BadRequestException : {}", e.getMessage()); + log.warn("handleBadRequestException() in GlobalExceptionHandler throw BadRequestException : {}", e.getMessage()); return HankkiResponse.fail(e.getErrorCode()); } @ExceptionHandler(UnauthorizedException.class) public HankkiResponse handleUnauthorizedException(UnauthorizedException e) { - log.error("handleUnauthorizedException() in GlobalExceptionHandler throw UnauthorizedException : {}", e.getMessage()); + log.warn("handleUnauthorizedException() in GlobalExceptionHandler throw UnauthorizedException : {}", e.getMessage()); return HankkiResponse.fail(e.getErrorCode()); } @ExceptionHandler(NotFoundException.class) public HankkiResponse handleEntityNotFoundException(NotFoundException e) { - log.error("handleEntityNotFoundException() in GlobalExceptionHandler throw EntityNotFoundException : {}", e.getMessage()); + log.warn("handleEntityNotFoundException() in GlobalExceptionHandler throw EntityNotFoundException : {}", e.getMessage()); return HankkiResponse.fail(e.getErrorCode()); } @ExceptionHandler(ConflictException.class) public HankkiResponse handleConflictException(ConflictException e) { - log.error("handleConflictException() in GlobalExceptionHandler throw ConflictException : {}", e.getMessage()); + log.warn("handleConflictException() in GlobalExceptionHandler throw ConflictException : {}", e.getMessage()); return HankkiResponse.fail(e.getErrorCode()); } @ExceptionHandler(MissingServletRequestParameterException.class) public HankkiResponse handleMissingServletRequestParameterException(MissingServletRequestParameterException e) { - log.error("handleMissingServletRequestParameterException() in GlobalExceptionHandler throw MissingServletRequestParameterException : {}", e.getMessage()); + log.warn("handleMissingServletRequestParameterException() in GlobalExceptionHandler throw MissingServletRequestParameterException : {}", e.getMessage()); return HankkiResponse.fail(BusinessErrorCode.BAD_REQUEST); } @ExceptionHandler(MaxUploadSizeExceededException.class) public HankkiResponse handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) { - log.error("handleMaxUploadSizeExceededException() in GlobalExceptionHandler throw MaxUploadSizeExceededException : {}", e.getMessage()); + log.warn("handleMaxUploadSizeExceededException() in GlobalExceptionHandler throw MaxUploadSizeExceededException : {}", e.getMessage()); return HankkiResponse.fail(StoreErrorCode.STORE_FILE_SIZE_EXCEEDED); } @ExceptionHandler(MethodArgumentNotValidException.class) public HankkiResponse handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { - log.error("handleMethodArgumentNotValidException() in GlobalExceptionHandler throw MethodArgumentNotValidException : {}", e.getMessage()); + log.warn("handleMethodArgumentNotValidException() in GlobalExceptionHandler throw MethodArgumentNotValidException : {}", e.getMessage()); + return HankkiResponse.fail(BusinessErrorCode.BAD_REQUEST); + } + + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + public HankkiResponse handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) { + log.warn("handleMethodArgumentTypeMismatchException() in GlobalExceptionHandler throw MethodArgumentTypeMismatchException : {}", e.getMessage()); + return HankkiResponse.fail(BusinessErrorCode.BAD_REQUEST); + } + + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + public HankkiResponse handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { + log.warn("handleHttpRequestMethodNotSupportedException() in GlobalExceptionHandler throw HttpRequestMethodNotSupportedException : {}", e.getMessage()); + return HankkiResponse.fail(BusinessErrorCode.BAD_REQUEST); + } + + @ExceptionHandler(NoResourceFoundException.class) + public HankkiResponse handleNoResourceFoundException(NoResourceFoundException e) { + log.warn("handleNoResourceFoundException() in GlobalExceptionHandler throw NoResourceFoundException : {}", e.getMessage()); + return HankkiResponse.fail(BusinessErrorCode.NOT_FOUND); + } + + @ExceptionHandler(HttpMessageNotReadableException.class) + public HankkiResponse handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { + log.warn("handleHttpMessageNotReadableException() in GlobalExceptionHandler throw HttpMessageNotReadableException : {}", e.getMessage()); return HankkiResponse.fail(BusinessErrorCode.BAD_REQUEST); } @ExceptionHandler(SdkClientException.class) public HankkiResponse handleSdkClientException(SdkClientException e) { - log.error("handleSdkClientException() in GlobalExceptionHandler throw SdkClientException : {}", e.getMessage()); + log.warn("handleSdkClientException() in GlobalExceptionHandler throw SdkClientException : {}", e.getMessage()); return HankkiResponse.fail(StoreImageErrorCode.STORE_IMAGE_UPLOAD_FAILED); } - @ExceptionHandler(BadGatewayException.class) - public HankkiResponse handleBadGatewayException(BadGatewayException e) { - log.error("handleBadGatewayException() in GlobalExceptionHandler throw BadGatewayException : {}", e.getMessage()); - return HankkiResponse.fail(e.getErrorCode()); - } - @ExceptionHandler(Exception.class) public HankkiResponse handleException(Exception e) { - log.error("handleException() in GlobalExceptionHandler throw Exception [{}] : {}", e.getClass() , e.getMessage()); + log.error("[500] INTERNAL SERVER ERROR({}) : {}",e.getClass() , e.getMessage()); return HankkiResponse.fail(BusinessErrorCode.INTERNAL_SERVER_ERROR); - } } diff --git a/src/main/java/org/hankki/hankkiserver/common/code/BusinessErrorCode.java b/src/main/java/org/hankki/hankkiserver/common/code/BusinessErrorCode.java index 78e8ba19..f40c7062 100644 --- a/src/main/java/org/hankki/hankkiserver/common/code/BusinessErrorCode.java +++ b/src/main/java/org/hankki/hankkiserver/common/code/BusinessErrorCode.java @@ -9,6 +9,7 @@ public enum BusinessErrorCode implements ErrorCode { BAD_REQUEST(HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), + NOT_FOUND(HttpStatus.NOT_FOUND, "요청한 자원을 찾을 수 없습니다."), INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류가 발생했습니다."); private final HttpStatus httpStatus;