Uploading a too-large file should be a 4xx client error, not a 500 Internal Server Error #27170
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
Milestone
When uploading a file that is too large (exceeding either
spring.servlet.multipart.max-file-size
orspring.servlet.multipart.max-request-size
), a 500 Internal Server Error is thrown. This seems odd to me, as this is an error due to an unsupported value sent by the client, not an unexpected server issue.It feels like a 4xx client error would be more appropriate for this situation, such as 413 Payload Too Large.
Workaround
This can be manually implemented in a Spring Boot application today by creating a custom
@ExceptionHandler
forMaxUploadSizeExceededException
. If the handler is set in the controller class, thespring.servlet.multipart.resolve-lazily
property must also be set totrue
:Example of current behavior
The text was updated successfully, but these errors were encountered: