Skip to content

fix(api_call): Handle JsonException on success response path#117

Merged
tharropoulos merged 2 commits intotypesense:masterfrom
eyupcanakman:fix/json-decode-success-path
Mar 9, 2026
Merged

fix(api_call): Handle JsonException on success response path#117
tharropoulos merged 2 commits intotypesense:masterfrom
eyupcanakman:fix/json-decode-success-path

Conversation

@eyupcanakman
Copy link
Contributor

Change Summary

PR #111 fixed uncaught JsonException on the error response path (non-2xx), but the success response path (2xx with asJson=true) still throws an uncaught JsonException when the server returns invalid JSON with a 2xx status code.

Wrap the success-path json_decode in a try/catch and re-throw as TypesenseClientError with the HTTP status code and a truncated response body for debugging.

Fixes #52

PR Checklist

eyupcanakman and others added 2 commits March 7, 2026 21:12
When a 2xx response contains invalid JSON and asJson is true,
json_decode with JSON_THROW_ON_ERROR throws an uncaught
JsonException. Wrap the call in a try/catch and re-throw as
TypesenseClientError with the HTTP status code and a truncated
response body for debugging.

Fixes typesense#52
@tharropoulos
Copy link
Collaborator

Thanks for the contribution!

@tharropoulos tharropoulos merged commit 6f61049 into typesense:master Mar 9, 2026
1 check passed
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.

Uncaught PHP Exception JsonException: "Syntax error" at /home/exceloid/OFC-ECOM/organic-api/vendor/typesense/typesense-php/src/ApiCall.php line 236

2 participants