Skip to content

fix(api-call): classify error responses with unparseable JSON bodies by status - #70

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

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

Conversation

@pcbeingused33

Copy link
Copy Markdown

ApiCall#perform_request parses any application/json body before it looks at the status code. When an error response carries an empty or malformed body (for example a 503 with nothing in it), JSON::ParserError escapes: the request is not retried on the next node, and callers do not get a Typesense::Error subclass.

An unparseable body on a non-2xx response is now ignored for the message, so the status picks the exception class as the README describes. 5xx is retried, other statuses raise right away with the message Error, and the raw body stays available in e.data[:response].body. A 2xx response with invalid JSON still raises JSON::ParserError, and valid JSON error bodies behave as before.

The new specs cover a 503 with an empty body followed by a 200, a 404 with an HTML body labelled as JSON, and a 200 with truncated JSON. The first two fail without the change; rubocop is clean.

This change was prepared with AI assistance.

…by status

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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