Skip to content

fix(api): canonical nested error envelope across the API (contract drift)#194

Merged
Depo-dev merged 1 commit into
mainfrom
fix/contract-drift
Jul 3, 2026
Merged

fix(api): canonical nested error envelope across the API (contract drift)#194
Depo-dev merged 1 commit into
mainfrom
fix/contract-drift

Conversation

@Depo-dev

@Depo-dev Depo-dev commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Part of the hardening sweep (item C: cross-language contract drift).

The Go API emitted several incompatible error shapes — flat {"error":"msg","code":"X"}, bare strings, {"error":{...}} without a code, top-level invalid_ids, and plain-text http.Error bodies — none matching the OpenAPI ErrorResponse schema ({"error":{"code","message"}}).

Both the TypeScript (parseApiError) and Python SDKs parse the nested envelope, so every real API error was mis-parsed and fell back to code=INTERNAL with the raw JSON as the message.

Fix: route all error responses through httputil.WriteError, which now emits the canonical nested {"error":{"code","message"}} shape (matching OpenAPI + both SDKs); add an UNAVAILABLE code for 503s. Converts stats, status, stream, batch, auth, and ratelimit; updates the tests that were asserting the old (wrong) shapes.

Verified locally: go build, go vet, go test ./... all green.

Note (not changed): OpenAPI's optional error.request_id vs the SDKs' optional error.field remain differently named; neither is emitted by the API today so it is latent only.

The Go API returned several incompatible error shapes — flat
{"error":"msg","code":"X"}, bare strings, {"error":{...}} without a
code, and plain-text http.Error bodies — none matching the OpenAPI
ErrorResponse schema ({"error":{"code","message"}}). Both the TS and
Python SDKs parse the nested envelope, so every real API error was
mis-parsed by the SDKs and fell back to code=INTERNAL with the raw body
as the message.

Route all error responses through httputil.WriteError, which now emits
the nested {"error":{"code","message"}} shape, and add an UNAVAILABLE
code for 503s. Converts stats, status, stream, batch, auth, and
ratelimit; updates the tests that asserted the old shapes.
@Depo-dev Depo-dev merged commit d3e34f9 into main Jul 3, 2026
8 checks passed
@Depo-dev Depo-dev deleted the fix/contract-drift branch July 3, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant