Skip to content

Instantly share code, notes, and snippets.

@roulupen
Created July 11, 2021 06:23
Show Gist options
  • Save roulupen/b1e0588b4ec651593fc2404048b7b7ff to your computer and use it in GitHub Desktop.
Save roulupen/b1e0588b4ec651593fc2404048b7b7ff to your computer and use it in GitHub Desktop.
@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