fix: read HTTP response bodies exactly once#43
Merged
Conversation
The error path consumed the one-shot Response body with response.json()
and then re-read it with response.text() in the catch, throwing
"Body is unusable: Body has already been read" and masking the real
(often non-JSON WAF/proxy HTML) response. The ok path silently returned
{} for any 200 without a JSON content-type. Port of the fix proven in
node-connectwise-automate (connectwise-automate-mcp#54).
github-actions Bot
pushed a commit
that referenced
this pull request
Jul 18, 2026
## [1.0.6](v1.0.5...v1.0.6) (2026-07-18) ### Bug Fixes * read HTTP response bodies exactly once ([#43](#43)) ([2333366](2333366)), closes [connectwise-automate-mcp#54](https://github.com/connectwise-automate-mcp/issues/54)
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.
Port of the single-read response fix proven in node-connectwise-automate#54 (root cause of connectwise-automate-mcp#54) — API calls returning
{}and then failing withBody is unusable: Body has already been read. The same defect existed verbatim in this repo'ssrc/http.ts.Root cause (src/http.ts handleResponse)
await response.json()(consumes the one-shot body stream, throws on non-JSON) thenawait response.text()in the catch on the same consumed body → undici'sBody is unusableTypeError, masking the real response. Hosted instances front the API with WAF/proxy HTML error pages, so this fires exactly when the diagnostics matter most.application/jsonreturned{}— login pages / WAF challenges read as successful-but-empty API calls.Fix
Read the body exactly once as text, then parse:
{}shape.HaloPsaErrorwith the content-type and a body snippet — surfacing WAF/proxy interference diagnosably instead of pretending success.src/auth.tsalready reads each response exactly once per branch — left untouched.Verification
tests/unit/http.test.tsusing realResponseobjects so one-shot body-stream semantics are actually exercised — against the unfixed code 4 of them fail with the exact reportedBody is unusableTypeError.