Repository navigation
fix: surface HTTP status and raw body in API errors - #322
Merged
Merged
Conversation
When an error response did not match the expected `{ error }` JSON shape
(empty body, HTML error page, or plain text from a proxy/CDN/load balancer
in front of the API), `formatAPIError` returned `undefined`, producing an
`APIError` with an empty message that was impossible to debug.
Fall back to the HTTP status (e.g. `HTTP 413 Payload Too Large`) and the
raw body, and attach `status`/`data` to `APIError`. Thread the response
through all `throwAPIError`/`formatAPIError` call sites.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Format APIError constructor / formatAPIError, and avoid conditional expect in the throwAPIError test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jsfez
approved these changes
Jun 23, 2026
This branch was successfully deployed
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.
Problem
A failed Argos build surfaced an
APIErrorwith no message:Root cause
formatAPIErrorreturnederror.error. When the error response body is not the expected{ error: "..." }JSON shape,error.errorisundefined, sonew APIError(undefined)produces an empty message.This happens when the error response does not originate from the Argos API itself:
errorHandleralways returns{ error: message }with a non-empty message.apiFetchalready turns any 5xx into"Internal Server Error (status)".So an empty message means a non-5xx (4xx) response from infrastructure in front of the API (proxy, load balancer, CDN, rate limiter) returning an empty body or an HTML/plain-text page — e.g.
413 Payload Too Large,429, a WAF403, etc.openapi-fetchthen setserrorto{}or a raw string, neither of which has.error.Fix
Make the formatter robust so the failure is always debuggable:
formatAPIError(error, response?)keeps the structured{ error, details }message when present, otherwise falls back to the HTTP status (e.g.HTTP 413 Payload Too Large) plus the raw body (truncated to 500 chars), and"Unknown API error"as a last resort.throwAPIError(error, response?)now accepts theresponseand attachesstatus+ rawdatato the thrownAPIError.APIErrorcarriesstatus?: numberanddata?: unknown(and setsname = "APIError").responseinto everythrowAPIError/formatAPIErrorcall site (core + cli).The original failure would now read e.g.
APIError: HTTP 413 Payload Too Largeinstead of a blank message.Tests
Added
packages/api-client/src/index.test.tscovering structured errors, empty-body status fallback, non-JSON bodies, truncation, and the enrichedAPIError. All api-client tests pass;check-typesis clean across api-client/core/cli.🤖 Generated with Claude Code