Spring MaxUploadSizeExceededException not handled ExceptionHandler

Viewed 19

I wanna handling MaxUploadSizeExceededException.

# application.properties

spring.servlet.multipart.resolve-lazily=true
server.tomcat.max-swallow-size=-1
spring.servlet.multipart.max-file-size=1MB
spring.servlet.multipart.max-request-size=1MB
@RestControllerAdvice
class MyControllerAdvice {
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public MyDTO myHandler(MaxUploadSizeExceededException ex) {
        log.error("ERROR!");
        return MyDTO.build();
    }
}

When I upload file large size, then it caught by application.properties and go to ExceptionHandler. And

  • swagger test

    • log is printed
    • response MyDTO
  • But web page's request

    • log is printed
    • but in my Chrome console, I cant see MyDTO
    • Chrome Network tab display failed to response data no data found for resource with given identifier

Why it doesn't work?

0 Answers
Related