Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request instantiation fails throw 400 Bad Response #1509

Closed
wants to merge 3 commits into from

Conversation

veryrusty
Copy link
Member

This started out as a patch for 1056; permitting deserialisation fails to use before hooks to alter the error thrown.

Since then, issues like #1496 and #1507 highlight that we want something more general in this regard. This PR changes behaviour, as what was previously a 500 Internal Server error when request object creation failed is now a 400 Bad Response error in line with the above issues.

Putting this out here for feedback and seeing if this is how we'd like to solve this.

veryrusty added 3 commits July 5, 2019 10:35
When a request that should be deserialized has bad content (such as
invalid JSON), the serializer throws an error and returns undef.
That gets caught and request object creation dies, which is then
handled in the App's psgi sub resulting in a 500 error.

When deserialisation fails, one typically does NOT want the client
repeating the request, in which case a 400 Bad Request error would be
more appropriate.

Wrap the request instantiation in an eval (with shim), so that we can
throw an error on deserialization failure.

By throwing an error in this way, we can send a serialized response
(another small win) rather than the plain text 500 error. PLUS ..
one can use the existing core.error.* hooks to modify the error as
needed, providing a solution to #1482.
This permits before error hooks to modify the error message before its
rendered. Includes test/example where deserialization failure returns
custom error code.
There's a grey area here between throwing a 400 Bad Request, and 500
Internal Error. As re-sending a failed request at this point is always
going to fail, send this as a 400 response; so the client doesn't try
again.

This is a change in behaviour in core; we always sent this as a 500
error before. However issues #1496, #1507 and #1056 point to a 400 error
being the better option.
@SysPete
Copy link
Member

SysPete commented Apr 11, 2020

👍 this is a clear improvement over current 500 response. I can also live with the status and message attributes switching to rw as this allows flexibility when needed.

@cromedome cromedome added this to the April 2020 Release milestone Apr 11, 2020
@cromedome
Copy link
Contributor

👍 Sorry for not approving this sooner - I was ready to but had to think through any consequences to changing the status of those attributes, then promptly dropped the ball. This is a solid fix. Thank you!

@cromedome
Copy link
Contributor

Merged, thank you!

@cromedome cromedome closed this Apr 11, 2020
@veryrusty veryrusty deleted the feature/deserialization_throws_400 branch April 13, 2020 01:26
cromedome added a commit that referenced this pull request May 27, 2020
    [ BUG FIXES ]
    * GH #1509: Request instantiation fails throw 400 Bad Response (Russell
      @veryrusty Jenkins). This resolves GH #1056, 1482, 1496, 1507, 1508,
      and 1510.

    [ ENHANCEMENTS ]
    * GH #1510: Test for proper multi-part form handing (ice-lenor, Sawyer X)
    * GH #1547: Cookie SameSite support (Russell @veryrusty Jenkins)

    [ DOCUMENTATION ]
    * None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants