11package org .avni .server .web ;
22
33import com .fasterxml .jackson .databind .exc .InvalidFormatException ;
4- import org .avni . server . domain . ValidationException ;
4+ import org .apache . tomcat . util . http . fileupload . impl . SizeLimitExceededException ;
55import org .avni .server .domain .accessControl .AvniAccessException ;
66import org .avni .server .domain .accessControl .AvniNoUserSessionException ;
77import org .avni .server .framework .rest .RestControllerErrorResponse ;
88import org .avni .server .util .BadRequestError ;
99import org .avni .server .util .BugsnagReporter ;
1010import org .avni .server .web .util .ErrorBodyBuilder ;
1111import org .springframework .beans .factory .annotation .Autowired ;
12+ import org .springframework .beans .factory .annotation .Value ;
1213import org .springframework .data .rest .webmvc .ResourceNotFoundException ;
1314import org .springframework .http .HttpHeaders ;
1415import org .springframework .http .HttpStatus ;
1819import org .springframework .web .bind .annotation .ExceptionHandler ;
1920import org .springframework .web .bind .annotation .RestControllerAdvice ;
2021import org .springframework .web .context .request .WebRequest ;
22+ import org .springframework .web .multipart .MaxUploadSizeExceededException ;
2123import org .springframework .web .servlet .mvc .method .annotation .ResponseEntityExceptionHandler ;
2224
2325import java .util .HashMap ;
2830
2931@ RestControllerAdvice
3032public class ErrorInterceptors extends ResponseEntityExceptionHandler {
33+
34+ private final String maxFileSize ;
3135 private final BugsnagReporter bugsnagReporter ;
3236 private final ErrorBodyBuilder errorBodyBuilder ;
3337
@@ -58,7 +62,8 @@ public void setMessage(String message) {
5862 }
5963
6064 @ Autowired
61- public ErrorInterceptors (BugsnagReporter bugsnagReporter , ErrorBodyBuilder errorBodyBuilder ) {
65+ public ErrorInterceptors (@ Value ("${spring.servlet.multipart.max-file-size}" ) String maxFileSize , BugsnagReporter bugsnagReporter , ErrorBodyBuilder errorBodyBuilder ) {
66+ this .maxFileSize = maxFileSize ;
6267 this .bugsnagReporter = bugsnagReporter ;
6368 this .errorBodyBuilder = errorBodyBuilder ;
6469 }
@@ -81,6 +86,11 @@ private ResponseEntity <RestControllerErrorResponse> error(final Exception excep
8186 return new ResponseEntity (new RestControllerErrorResponse (errorBodyBuilder .getErrorBody (message )), httpStatus );
8287 }
8388
89+ @ ExceptionHandler (value = {MaxUploadSizeExceededException .class , SizeLimitExceededException .class })
90+ public ResponseEntity fileUploadSizeLimitExceededError (Exception e ) {
91+ return ResponseEntity .badRequest ().body (String .format ("Maximum upload file size exceeded; ensure file size is less than %s." , maxFileSize ));
92+ }
93+
8494 @ ExceptionHandler (value = {Exception .class })
8595 public ResponseEntity unknownException (Exception e ) {
8696 if (e instanceof BadRequestError ) {
0 commit comments