Handle non-JSON responses in CurlSender gracefully#65
Merged
AlexVanderbist merged 2 commits intomainfrom Feb 23, 2026
Merged
Conversation
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.
92b4be8 to
a162ded
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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), butApi::test()has no try/catch, so the ConnectionError propagated up to the caller. In configs that useCurlSender, this brokeflare:test. The command would report a connection error despite the request having succeeded.The fix replaces the
json_decode+json_last_errorcheck withjson_decode($json, true) ?? $json, matching whatLaravelHttpSenderalready does. Valid JSON is decoded to an array; anything else passes through as a raw string.Response::$bodyis 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.