Fix API returning HTML error pages when user sends invalid JSON
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:
- Closes #11717
Special notes for your reviewer:
- Let me know if GSON, Jackson etc should be added to the list of implementations.
- Let me know if there should be a line in the API changelog about this. It affects a lot of API endpoints.
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:
$ http POST http://localhost:8080/api/admin/bannerMessage --raw="{test}"
HTTP/1.1 500 Internal Server Error
Connection: close
Content-Length: 284
Content-Type: application/json;charset=UTF-8
Server: Payara Server 6.2025.3 #badassfish
X-Frame-Options: SAMEORIGIN
X-Powered-By: Servlet/6.0 JSP/3.1 (Payara Server 6.2025.3 #badassfish Java/Eclipse Adoptium/17)
{
"code": 500,
"incidentId": "5cbfad8c-4a7a-4faf-8470-42c684da9721",
"interalError": "JsonParsingException",
"message": "Internal server error. More details available at the server logs.",
"requestMethod": "POST",
"requestUrl": "http://localhost:8080/api/v1/admin/bannerMessage",
"status": "ERROR"
}
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:
$ http PUT http://localhost:8080/api/admin/settings/test --raw="test"
HTTP/1.1 500 Internal Server Error
Connection: close
Content-Length: 319
Content-Type: application/json;charset=UTF-8
Server: Payara Server 6.2025.3 #badassfish
X-Frame-Options: SAMEORIGIN
X-Powered-By: Servlet/6.0 JSP/3.1 (Payara Server 6.2025.3 #badassfish Java/Eclipse Adoptium/17)
{
"code": 500,
"incidentId": "206716ef-f1de-4b5e-9e48-e7ed100f8e4f",
"interalError": "RollbackException",
"internalCause": "PersistenceException",
"message": "Internal server error. More details available at the server logs.",
"requestMethod": "PUT",
"requestUrl": "http://localhost:8080/api/v1/admin/settings/test",
"status": "ERROR"
}
As a curl command, this would be: curl -X PUT -d "test" http://localhost:8080/api/admin/settings/test
Watch the server log! :smile: (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?