Skip to content

Add error handling for too large JSON payloads#973

Closed
Nilix007 wants to merge 1 commit intorwf2:masterfrom
Nilix007:error-handling-too-large-json-payload
Closed

Add error handling for too large JSON payloads#973
Nilix007 wants to merge 1 commit intorwf2:masterfrom
Nilix007:error-handling-too-large-json-payload

Conversation

@Nilix007
Copy link
Copy Markdown

Hi,

This PR adds error handling for too large JSON payloads. It also adds a new JsonError PayloadTooLarge so that this case can be handled properly. Fixes #972.

Old behaviour for too large JSON payloads:

POST / application/json:
    => Matched: POST / (x)
    => Warning: Data left unread. Force closing network stream.
    => Error: Couldn't parse JSON body: Error("EOF while parsing a string", line: 1, column: 1048576)
    => Outcome: Failure
    => Warning: Responding with 400 Bad Request catcher.
    => Response succeeded.

New behaviour:

POST / application/json:
    => Matched: POST / (x)
    => Error: JSON payload too large.
    => Warning: Data left unread. Force closing network stream.
    => Outcome: Failure
    => Warning: Responding with 413 Payload Too Large catcher.
    => Response succeeded.

@jebrosen
Copy link
Copy Markdown
Collaborator

I like the idea. I think it would be great if Rocket provided an easy way to do this and could share the implementation with Form and anything else that has a limit.

This also adds a new `JsonError` `PayloadTooLarge` so that this case can
be handled properly.
@Nilix007 Nilix007 force-pushed the error-handling-too-large-json-payload branch from 323a2c6 to 389050b Compare April 13, 2019 16:43
@hellow554
Copy link
Copy Markdown

ping @jebrosen any more concerns? I'd like to see this in rocket!

@Nilix007
Copy link
Copy Markdown
Author

Nilix007 commented May 6, 2019

I opened #990 which shall provide a general solution for all body data parsers.

Let's continue over there.

@Nilix007 Nilix007 closed this May 6, 2019
@SergioBenitez SergioBenitez added the pr: closed This pull request was not merged label May 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: closed This pull request was not merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return a 413 instead of 400 when data limit is exceeded

4 participants