Aggregate body errors[] messages in HttpError.from()#2
Merged
Conversation
When a response body carries an errors[] envelope (GraphQL data.errors[],
REST errors[], etc.), surface every errors[].message joined by '; ' as
err.message instead of the default '${status} ${statusText}'. Codes and any
other per-error fields stay accessible via err.json.errors[].
Aggregation runs regardless of HTTP status, so a 200-with-errors response
and a 4xx-with-errors response both produce a fully populated HttpError
when passed to from().
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Coverage Report for CI Build 25708010537Coverage remained the same at 100.0%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
GraphQL's spec mandates errors[].message; JSON:API uses errors[].detail with title as a short summary. Both are widely used 'errors[]' envelope shapes, so picking the first present field across the three keeps the aggregation useful for either without forcing callers to override the message themselves. Drops the RFC 9457 reference — Problem Details is a top-level object, not a nested errors[] envelope, so the aggregation block doesn't apply. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
JSON:API title is a category/summary that shouldn't change between occurrences, so it's a weak per-instance message. Sticking with message and detail gives clean 2-for-2 coverage of GraphQL and JSON:API. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…pattern response.clone() throws synchronously when the body has been disturbed, so wrap the body read in try/catch. After a caller does response.json() and then needs to throw on an in-body errors envelope, calling from() again no longer crashes — it returns a baseline HttpError with the status message. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
When a response body carries an `errors[]` envelope, `from()` now surfaces every `errors[].message` joined by `; ` as `err.message` instead of the default `"${status} ${statusText}"`.
This is the established convention for APIs that don't rely solely on HTTP status codes to signal failure:
Aggregation runs regardless of HTTP status, so a 200-with-errors response and a 4xx-with-errors response both produce a fully populated `HttpError`. Codes and any other per-error fields stay accessible via `err.json.errors[]`.
Test plan
🤖 Generated with Claude Code