fix: parse GraphQL errors from response body on HTTP 4xx/5xx status codes#1457
Merged
jasonkuhrt merged 1 commit intoNov 10, 2025
Merged
Conversation
…odes Fixes regression from v6 to v7 where HTTP 4xx/5xx responses would throw ClientError without including the GraphQL errors from the response body. Changes: - Parse response body BEFORE checking HTTP status in runRequest.ts - Include parsed GraphQL response data in ClientError when status is non-2xx - Add comprehensive test suite for various HTTP error status codes (422, 500, 404, 403, 400) This restores the v6 behavior where users can access response.errors even when the server returns a non-2xx HTTP status code. Closes #1281
2bb27f2 to
f93bdca
Compare
jasonkuhrt
added a commit
that referenced
this pull request
Nov 11, 2025
Fixes #1458 PR #1457 exposed a pre-existing bug where non-JSON error responses (like HTML 502 pages from load balancers) caused an unhelpful error: "Invalid execution result: result is not object or array" Changes: - Modified parseResultFromResponse to safely attempt JSON parsing in the ELSE branch before failing - Returns descriptive error messages for non-JSON responses - Added comprehensive test coverage for HTML, plain text, and missing Content-Type scenarios - Maintains backward compatibility for servers that omit Content-Type but still return valid JSON The fix handles common production scenarios: - Load balancer errors (502/503 with HTML) - CDN errors (CloudFlare, Akamai) - Misconfigured servers - Rate limiters returning plain text
jasonkuhrt
added a commit
that referenced
this pull request
Nov 11, 2025
* Fix: handle non-JSON error responses gracefully Fixes #1458 PR #1457 exposed a pre-existing bug where non-JSON error responses (like HTML 502 pages from load balancers) caused an unhelpful error: "Invalid execution result: result is not object or array" Changes: - Modified parseResultFromResponse to safely attempt JSON parsing in the ELSE branch before failing - Returns descriptive error messages for non-JSON responses - Added comprehensive test coverage for HTML, plain text, and missing Content-Type scenarios - Maintains backward compatibility for servers that omit Content-Type but still return valid JSON The fix handles common production scenarios: - Load balancer errors (502/503 with HTML) - CDN errors (CloudFlare, Akamai) - Misconfigured servers - Rate limiters returning plain text * fix: format and lint issues - Use backticks instead of single quotes for consistency - Fix string concatenation formatting - Break long test fixture line
jasonkuhrt
added a commit
that referenced
this pull request
Nov 17, 2025
This reverts: - a9f94c1 chore: bump ver (7.3.3) - 97d9822 Fix: handle non-JSON error responses gracefully (#1459) - cc99d03 chore: bump version to 7.3.2 - 7a1ee76 fix: parse GraphQL errors from response body on HTTP 4xx/5xx status codes (#1457) Reason: The approach of parsing body first then checking status led to cascading issues: - #1461: ClientError replaced with generic Error for auth failures - #1462: Unhelpful error messages for 401 responses Will reimplement with a cleaner approach that: - Returns ClientError for ALL non-2xx responses - Preserves access to GraphQL errors in 4xx/5xx responses (#1281) - Provides helpful error messages for parse failures
This was referenced Nov 17, 2025
jasonkuhrt
added a commit
that referenced
this pull request
Nov 17, 2025
This reverts: - a9f94c1 chore: bump ver (7.3.3) - 97d9822 Fix: handle non-JSON error responses gracefully (#1459) - cc99d03 chore: bump version to 7.3.2 - 7a1ee76 fix: parse GraphQL errors from response body on HTTP 4xx/5xx status codes (#1457) Reason: The approach of parsing body first then checking status led to cascading issues: - #1461: ClientError replaced with generic Error for auth failures - #1462: Unhelpful error messages for 401 responses Will reimplement with a cleaner approach that: - Returns ClientError for ALL non-2xx responses - Preserves access to GraphQL errors in 4xx/5xx responses (#1281) - Provides helpful error messages for parse failures
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
Fixes regression from v6 to v7 where HTTP 4xx/5xx responses would throw
ClientErrorwithout including the GraphQL errors from the response body.Changes
runRequest.ts:74-102ClientErrorwhen HTTP status is non-2xxRationale
In v6, when a server returned a 4xx/5xx HTTP status with a valid GraphQL response body containing errors, users could access those errors via
error.response.errors. This was a common pattern for handling authentication errors (422), server errors (500), etc.The v7 implementation in
runRequest.tscheckedfetchResponse.okbefore parsing the response body, which meant the GraphQL errors were never extracted and included in theClientError. This broke user code that relied on accessing error details.Solution
The fix moves the
parseResultFromResponse()call to happen before the HTTP status check. This ensures:ClientErrorincludes both HTTP metadata (status, headers) AND GraphQL response data (errors, data)Test Plan
Closes #1281