Skip to content

Detect all common size exceptions from Tomcat and Commons FileUpload 2.x #36317

@osiegmar

Description

@osiegmar

With #19204, explicit handling of FileSizeLimitExceededException was added alongside SizeLimitExceededException. This should be extended to handle FileCountLimitExceededException as well.

Currently, requests that exceed the configured size limit are handled by Spring, and an HTTP 413 Content Too Large response is returned to the client.

However, when a multipart request exceeds the maximum number of parts, a FileCountLimitExceededException is thrown. This exception is not handled by Spring, which ultimately results in an HTTP 500 Internal Server Error response. This does not only cause confusion for clients, but also triggers monitoring/alerting systems that are configured to detect server errors.

To fix this inconsistency, FileCountLimitExceededException should be explicitly caught and handled.

My current workaround is to add the following method to a @ControllerAdvice class of my application:

@ExceptionHandler(FileCountLimitExceededException.class)
@ResponseStatus(HttpStatus.CONTENT_TOO_LARGE)
public void handleFileCountLimitExceededException() {}

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchesstatus: feedback-providedFeedback has been providedtype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions