Skip to content

fix: Return specific error message when multipart body limit is exceeded#3611

Open
AndreaBozzo wants to merge 1 commit intotokio-rs:mainfrom
AndreaBozzo:fix/multipart-body-limit-error-message
Open

fix: Return specific error message when multipart body limit is exceeded#3611
AndreaBozzo wants to merge 1 commit intotokio-rs:mainfrom
AndreaBozzo:fix/multipart-body-limit-error-message

Conversation

@AndreaBozzo
Copy link

@AndreaBozzo AndreaBozzo commented Jan 1, 2026

  • When a multipart request exceeds the body limit, the response now returns "Request payload is too large" instead of a generic parsing error message
  • The status code was already correct (413 PAYLOAD_TOO_LARGE), only the message was generic

Test plan

  • Updated existing body_too_large tests in both axum and axum-extra to verify the error message
  • cargo test passes
  • cargo fmt
  • cargo clippy passes

Fixes #3216

When a multipart request exceeds the body limit, the response now returns
"Request payload is too large" instead of a generic parsing error message.
The status code was already correct (413 PAYLOAD_TOO_LARGE).

Fixes: tokio-rs#3216
@AndreaBozzo
Copy link
Author

Thank you for approving this PR, have a nice day

@jplatte
Copy link
Member

jplatte commented Jan 13, 2026

I would like to investigate what error messages we got before and why, before merging this. If somebody else wants to do that, it could speed up the release of this.

@jplatte jplatte added this to the 0.9 milestone Jan 13, 2026
@AndreaBozzo
Copy link
Author

AndreaBozzo commented Jan 13, 2026

I would like to investigate what error messages we got before and why, before merging this. If somebody else wants to do that, it could speed up the release of this.

Hi @jplatte , i just checked in this morning as i had the branch laying, there is absolutely no rush on my part and i appreciate your attenction

About the change, i struggled a bit on understanding how complex the error pathing is as its wrapped into multiple layer and i'm admittedly new to this codebase.

Before this PR, body_text() simply called .to_string() on the multer error, which produced something like:

error reading a body from connection: Request payload is too large

The status code (413) was already correct thanks to status_code_from_multer_error(), but the response body was the raw multer error message instead of the more straigtforward "Request payload is too large".

Is this needed? not strictly, but i'm guessing it can be useful

Open to any feedback / suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong error when body limit is hit while parsing a multipart upload

3 participants