How to customize the "413 Payload Too Large" response in Quarkus with multipart/form-data requests?
I'm working with a Java 21 Quarkus (3.18.1) API that uses the quarkus.http.limits.max-form-attribute-size
property to limit request body size. When a request body exceeds this limit, the application automatically responds with a "413 Payload Too Large" error.
I want to customize this response to return a custom JSON payload that maintains a consistent response schema across my application.
The HTTP requests to my API use multipart/form-data
with both text fields and file uploads. For example:
curl --request POST \
--url http://localhost:8080/api \
--header 'content-type: multipart/form-data' \
--form 'text=content' \
--form 'document=@C:\path\to\file.pdf'
How can I intercept and customize the "413 Payload Too Large" response for these multipart requests?
Any suggestions about the best approach to handle this would be appreciated.