-
Notifications
You must be signed in to change notification settings - Fork 165
Catch JSON deserialization exceptions and use them to return 400 errors #581
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
Catch JSON deserialization exceptions and use them to return 400 errors #581
Conversation
…r codes This code adds the JSON deserialization exception to GraphQLRequestDeserializationResult and sets IsSuccessful = false. Also, unmatched content-type should return 415 error code: Unsupported Media Type
|
This addresses some of the issues from #580 |
Shane32
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but @sungam3r should review.
src/Transports.AspNetCore.NewtonsoftJson/GraphQLRequestDeserializer.cs
Outdated
Show resolved
Hide resolved
sungam3r
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need small changes in the API design. I'm OK to merge after that.
|
Hello, Thanks in advance ! |
|
I was waiting on feedback on how to propagate the exceptions and then forgot about this. I can update the PR :) |
- This replaces IsSuccessful in GraphQLRequestDeserializationResult - Made GraphQLRequestDeserializationException as a common exception wrapper for both NewtonsoftJson and System.Text.Json
|
Thanks @jeffw-wherethebitsroam ! Did the API surface change? We might need the apiapprovals file updated. Also it looks like it is failing the formatting check. |
|
@jeffw-wherethebitsroam I found the issue with the formatting tool; if you can merge master back into this branch, then it should run the CI tests properly. |
|
@Shane32 I've merged master. The API surface did change (removed IsSuccessful from GraphQLRequestDeserializationResult, added GraphQLRequestDeserializationException), but the apiapprovals file is updated. |
|
@Shane32 It looks like I need a maintainer to approve the workflows: "First-time contributors need a maintainer to approve running workflows" |
|
I think these changes look great! However, it contains breaking changes in the API surface, and has breaking changes to the semantics of the current request parsing methods. It really belongs in the next major version, I would think. To make this a non-breaking change, we could retain the The remainder of the semantic changes, such as returning the proper status code upon failure, would only necessitate a bump to the minor version number. There is one other alternative to getting these changes in the current version, and that would be to leave the Thoughts? |
Removing IsSuccessful is a breaking API change. So add it back in so this PR can go in. However, this means it is possible for IsSuccessful to be false with no exception, so check for this.
…thebitsroam/server into handle-json-deserialization-errors
|
Ok, we're now pretty much back to the original version :) Its a bit uglier now since |
|
I just have so little time to spend on the next version, and there’s a whole lot of cleanup that could be done. Better to get this fix in the current version. |
|
@jeffw-wherethebitsroam Thanks for this fix. Just reviewed it. LGTM, just a few cosmetic changes here. I had a long break from OSS this year but I returned. I think that when I read the remaining emails for this repo (~60 left), then I can release v5.1 including this fix (and others of course). |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #581 +/- ##
==========================================
+ Coverage 54.84% 55.51% +0.67%
==========================================
Files 63 64 +1
Lines 1506 1531 +25
Branches 152 154 +2
==========================================
+ Hits 826 850 +24
Misses 627 627
- Partials 53 54 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This code adds the JSON deserialization exception to
GraphQLRequestDeserializationResult and sets IsSuccessful = false.
Also, unmatched content-type should return 415 error code: Unsupported Media Type