Skip to content

Handle non-JSON responses in CurlSender gracefully#65

Merged
AlexVanderbist merged 2 commits intomainfrom
fix-curlsender-for-empty-response
Feb 23, 2026
Merged

Handle non-JSON responses in CurlSender gracefully#65
AlexVanderbist merged 2 commits intomainfrom
fix-curlsender-for-empty-response

Conversation

@AlexVanderbist
Copy link
Member

CurlSender::post() strictly validated the API response as JSON, throwing a ConnectionError on empty or non-JSON bodies, even when the HTTP request succeeds.

This was masked for normal Api::report() calls (which silently catch all exceptions), but Api::test() has no try/catch, so the ConnectionError propagated up to the caller. In configs that use CurlSender, this broke
flare:test. The command would report a connection error despite the request having succeeded.

The fix replaces the json_decode + json_last_error check with json_decode($json, true) ?? $json, matching what LaravelHttpSender already does. Valid JSON is decoded to an array; anything else passes through as a raw string. Response::$body is typed mixed, so both are fine.

Also extracts a protected executeCurl() method as a testing seam and adds unit tests covering empty bodies, non-JSON bodies, valid JSON, and curl failures.

Extract curl_exec into a protected method for testability.
Instead of throwing ConnectionError on invalid JSON, fall
back to the raw response string. Add tests covering empty,
non-JSON, valid JSON, and failed curl responses.
Extract executeRequest() method in GuzzleSender (mirrors CurlSender's
executeCurl() pattern) and add Pest tests covering empty, non-JSON, and
valid JSON response bodies.
@AlexVanderbist AlexVanderbist force-pushed the fix-curlsender-for-empty-response branch from 92b4be8 to a162ded Compare February 23, 2026 14:26
@AlexVanderbist AlexVanderbist merged commit 69a158b into main Feb 23, 2026
19 checks passed
@AlexVanderbist AlexVanderbist deleted the fix-curlsender-for-empty-response branch February 23, 2026 14:26
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