-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Handle JsonExceptions in RequestDelegateFactory #36589
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
Conversation
InvalidDataException is what's thrown by the form parser. Was this accidentally copied from that code path? |
@halter73 are you returning 400 to be consistent with MVC? Any reason why we are not returning 422 ? |
I mostly did this to be consistent with MVC and our current InvalidDataException behavior. Also, the rfc claims
And I think JsonExceptions indicate the JSON is not "well-formed". A 422 would be more appropriate if the request was missing a required property or something like that (assuming that was something we supported). |
7de673f
to
0bbbb7f
Compare
/backport to release/6.0-rc2 |
Started backporting to release/6.0-rc2: https://github.com/dotnet/aspnetcore/actions/runs/1243143334 |
@halter73 backporting to release/6.0-rc2 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Handle JsonExceptions like InvalidDataExceptions in RequestDelegateFactory
Using index info to reconstruct a base tree...
M src/Http/Http.Extensions/src/RequestDelegateFactory.cs
M src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
Auto-merging src/Http/Http.Extensions/src/RequestDelegateFactory.cs
Applying: Don't catch InvalidDataExceptions when reading JSON
Using index info to reconstruct a base tree...
M src/Http/Http.Extensions/src/RequestDelegateFactory.cs
M src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
CONFLICT (content): Merge conflict in src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
Auto-merging src/Http/Http.Extensions/src/RequestDelegateFactory.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 Don't catch InvalidDataExceptions when reading JSON
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@captainsafia Can you approve this PR too? Thanks! |
This change causes minimal API route handlers to respond with a "400 Bad Request" instead of "500 Internal Server Error" when given a request body with an
application/json
Content-Type but malformed JSON.Before, we expected this to throw an
InvalidDataException
but malformed JSON results in aJsonException
instead.I plan to backport this to
release/6.0-rc2
.Fixes #36499