spring-framework
spring-framework copied to clipboard
DataBufferLimitException in WebFlux controllers should result in 413 instead of 500
When using Spring WebFlux, there is a maximum limit on the payload size, defined by spring.codec.max-in-memory-size
(default value is 256KB). If a request is made with a body exceeding this size, DataBufferLimitException
is thrown. The default error handler then returns a 500 Internal Server Error
response. This is actually not a server side error, but instead a server side validation. This should result in 413 Content Too Large
instead.
Spring Boot version: 3.2.1
Few more thoughts: the error handler probably shouldn't map DataBufferLimitException
to 413
directly, as there can be other reasons for the exception. For example, WebClient
can also throw this exception, which likely is a server side error. I suppose we should map (i.e. onErrorMap
) to another exception that always result in a 413
; this should only happen when parsing the body of request. But I'm not very familiar with the spring-framework code, so just guessing.
Also, I do not know if this happens in WebMVC all well; that is a 500 instead of a 413, but it should be straightforward to validate.
Closing in favor of PR #32558