Created
July 11, 2021 06:23
-
-
Save roulupen/b1e0588b4ec651593fc2404048b7b7ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ControllerAdvice("com.storageservice.document") | |
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { | |
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); | |
@ExceptionHandler(MaxUploadSizeExceededException.class) | |
@ResponseStatus(HttpStatus.PAYLOAD_TOO_LARGE) | |
public ResponseEntity<Object> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException maxUploadSizeExceededException, | |
WebRequest request) { | |
return buildErrorResponse("File size too large!", HttpStatus.PAYLOAD_TOO_LARGE); | |
} | |
private ResponseEntity<Object> buildErrorResponse(String message, | |
HttpStatus httpStatus) { | |
ErrorResponse errorResponse = new ErrorResponse(httpStatus.value(), message); | |
return ResponseEntity.status(httpStatus).body(errorResponse); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment