-
Notifications
You must be signed in to change notification settings - Fork 530
Fix API returning HTML error pages when user sends invalid JSON #11945
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
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@poikilotherm Please resolve conflicts |
|
@poikilotherm I bumped this to 6.10. Also, please resolve merge conflicts. Thanks! |
…1717 - Replaced `JsonParseExceptionHandler` with `JsonExceptionsHandler` to streamline exception handling - Added mappers for `JsonParsingException` and `DvUtilJsonParseException`
- Ensured API returns `BAD_REQUEST` for malformed JSON input with appropriate error message validation - Makes sure invalid JSON is not resulting in a HTML error page
…ponse creation #11717 - Cloned JsonObjectBuilder to prevent unintended mutation - Simplified metadata construction logic in logging - This should allow us to no longer have HTML Error 500 pages, but a nicer JSON response.
f0e2408 to
b919120
Compare
|
@pdurbin I made a rebase and force pushed. There were ~300 commits missing, to this is the cleaner fix, avoiding any merge conflicts. |
This comment has been minimized.
This comment has been minimized.
|
Re: Let me know if GSON, Jackson etc should be added to the list of implementations. I did some testing with unit tests and IT tests that make calls where Gson reads json. The IT tests returned 400 and appropriate exceptions were returned when invalid json was given. I don't believe we need to make changes here. As for the API changelog, I didn't see any mention of an expected 500 for the response. I would say that it's not a change as most people would assume it should return 400. Approving this pr |
This comment has been minimized.
This comment has been minimized.
|
📦 Pushed preview images as 🚢 See on GHCR. Use by referencing with full name as printed above, mind the registry name. |
What this PR does / why we need it:
Ensure any JSON parsing errors do not result in HTML error pages.
Which issue(s) this PR closes:
Special notes for your reviewer:
Suggestions on how to test this:
I added an API test with one of the affected endpoints. Just execute the test before applying the patches and after.
I also wanted to fix the catchall error handler I tried to implement some time ago. For that, I had to modify the logging in the
JsonResponseBuilder. The situation where sending invalid JSON to the endpoints results in a HTML response was not reproducible for me. Please test again!Here's how a response looks like when not applying the JSON error handler, but with the fix for the logging:
With the JSON error handler, this is now an error 400 (as it should be), but in case other exceptions bubble up...
An example to test this with the JSON handler in place:
As a
curlcommand, this would be:curl -X PUT -d "test" http://localhost:8080/api/admin/settings/testWatch the server log! 😄 (BTW I tested this with the Dockerized Dev Instance using
mvn -Pct package docker:run)Does this PR introduce a user interface change? If mockups are available, please link/include them here:
Not within the UI, but of course the API "user interface".
Is there a release notes update needed for this change?:
Maybe?
Additional documentation:
None?