Skip to content

fix: keep status code and body for non-JSON error responses - #448

Open
pcbeingused33 wants to merge 1 commit into
crowdin:masterfrom
pcbeingused33:fix/c6571-non-json-error-body
Open

pcbeingused33 wants to merge 1 commit into
crowdin:masterfrom
pcbeingused33:fix/c6571-non-json-error-body

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

When a request fails with a body that is not JSON (an HTML page from a proxy on 502/504/413, or an empty body), ApacheHttpClient.request passes it to the JSON parser without keeping the status code. The parser's IOException is then caught by the generic handler, so the caller gets an HttpException whose message is a Jackson parse error, with error.code and httpResponse both null. A response with no entity (for example a failed HEAD) throws NullPointerException instead.

In these cases the client now throws an HttpException with error.code set to the HTTP status, the message HTTP error <status> and httpResponse set to the raw body (null when there is no entity). JSON error responses are parsed as before.

Three cases added to ApacheHttpClientTest (HTML body, empty body, no entity) fail without the change; ./gradlew test passes with it (904 tests).

AI assistance was used to prepare the patch and regression tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant