Skip to content

Wrap a response body that breaks off mid-read in an IncompleteResponseException - #30

Merged
loevgaard merged 3 commits into
1.xfrom
fix/incomplete-response-body
Nov 16, 2026
Merged

loevgaard merged 3 commits into
1.xfrom
fix/incomplete-response-body

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Summary

Closes #29.

 Client::request()
   sendRequest()                        ClientExceptionInterface → TransportException
+  read the body once                   \RuntimeException        → IncompleteResponseException
+  response->withBody(buffered copy)    re-readable, even from a non-seekable stream
   record lastRequest / lastResponse
   assertStatusCode()

One deliberate deviation from the agent brief: IncompleteResponseException implements only QuickpayException, not PSR-18 NetworkExceptionInterface. PSR-18 defines that as "no response received", but here the status and headers did arrive, so a capture or refund may have gone through. It must not look like a safe-to-retry network error. Adding a PSR-18 interface later stays BC-safe; removing one would not.

Evidence

The issue's reproduction (Symfony MockHttpClient → Psr18Client 7.4 → nyholm/psr7 1.8.2, PHP 8.4), with status 200 and 500:

  • Before: RuntimeException: Unable to read stream contents: Connection reset by peer, thrown via decodeJson() (200) and assertStatusCode() (500). Not a QuickpayException.
    After: IncompleteResponseException: The response body could not be read in full [GET https://api.quickpay.net/ping] (status code: 200): Unable to read stream contents: Connection reset by peer. It is a QuickpayException.

New tests, through ScriptedHttpClient plus a NonSeekableStream test double:

200 | 500 response whose body throws mid-read
  ping()                         → IncompleteResponseException (previous = stream error, status kept)
  getLastRequest/LastResponse    → the attempt; body reads '' instead of throwing again
  message                        → method + URI without query + status + stream error, no API key
non-seekable body that reads fine
  get()                          → decodes it; getLastResponse() body still equals what the server sent
  request()                      → returned body readable twice
  non-JSON body                  → MalformedResponseException; getLastResponse() keeps the body
IncompleteResponseException      → is a QuickpayException, is NOT a PSR-18 ClientExceptionInterface

220 tests pass. PHPStan (max), ECS and Rector are clean, and Infection gives MSI 88% / covered 89%.

Merge Danger

Door: Two-way until tagged

Once it's released, IncompleteResponseException is public API, so removing it would be a 2.0 change.

Blast Radius: Every request

Every call now reads the body eagerly. request() returns a buffered copy of the body instead of the HTTP client's live stream. Quickpay answers are small JSON documents. Existing catch blocks keep working: the new exception extends \RuntimeException, so the Setono/SyliusQuickpayPlugin#175 workaround still catches it.

@codecov

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.17%. Comparing base (c339113) to head (b9fd7ef).

Additional details and impacted files
@@             Coverage Diff              @@
##                1.x      #30      +/-   ##
============================================
+ Coverage     99.14%   99.17%   +0.03%     
- Complexity      226      230       +4     
============================================
  Files            27       28       +1     
  Lines           582      605      +23     
============================================
+ Hits            577      600      +23     
  Misses            5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@loevgaard
loevgaard merged commit 9a92017 into 1.x Nov 16, 2026
36 checks passed
@loevgaard
loevgaard deleted the fix/incomplete-response-body branch November 16, 2026 08:45
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.

Wrap a response body that breaks off mid-read in a QuickpayException

1 participant