Accept an already-parsed body in HttpError.from() (1.2.0)#3
Merged
Conversation
`from(response, json)` uses a body you've already read instead of re-reading the response — for a 200 response with an `errors[]` envelope, where the body is consumed by `response.json()`. `from(response)` is unchanged. The error still carries the response status and `cause`. Also reformats the changelog to Keep a Changelog, matching the other packages. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Coverage Report for CI Build 26485767779Coverage decreased (-3.7%) to 96.341%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
Summary
HttpError.from()gains an optional second argument — an already-parsed JSON body:from(response)— unchanged; reads the body viaresponse.clone().from(response, json)— uses the body you already read instead of re-reading the response.This fixes the common pattern where a 200 response carries an
errors[]envelope: once you've read the body withawait response.json(), the response stream is consumed, so a secondfrom(response)can't read it (you get a bare"200 OK"). Passing the parsed body —from(response, json)— captures the detail, and the error still carries the response status andcause.Backward compatible —
from(response)behavior is identical.Also
CHANGELOG.mdto Keep a Changelog, matching the other@stores.compackages.Testing
node --test— 15 pass / 0 fail; eslint clean. New tests coverfrom(response, json)(uses the passed body without re-reading, JSON:APIdetail, status-message fallback).🤖 Generated with Claude Code