Stack Exchange
Handle MaxUploadSizeExceededException in global exception handler with Spring Boot
I'm trying to handle MaxUploadSizeExceededException in global exception handler with Spring Boot during upload a big file. I catch the exception in class extending ResponseEntityExceptionHandler and return ResponseEntity by calling the method handleExceptionInternal. But on the client side I don't get this entity, but I get ERR_CONNECT_RESET.
Global Exception handler:
@ControllerAdvice
class ControllerExceptionHandler () : ResponseEntityExceptionHandler() {
    val log: Logger = LoggerFactory.getLogger(this::class.java)

    @ExceptionHandler(MaxUploadSizeExceededException::class)
    @ResponseStatus(HttpStatus.PAYLOAD_TOO_LARGE)
    protected fun uploadSizeExceptionHandler(ex: MaxUploadSizeExceededException,  request: WebRequest): ResponseEntity<Any> {
        log.error(ex.message)
        return handleExceptionInternal(ex, AttachResult("Максимальный размер файла 10MB"), HttpHeaders(), HttpStatus.PAYLOAD_TOO_LARGE, request)
    }
}

application.yml
spring:
  servlet:
    multipart:
      max-file-size: 10MB
      max-request-size: 10MB
      resolve-lazily: true

