Skip to content

fix: Preserve raw HTTP error status and bodies for non-schema errors#5820

Closed
darrendc26 wants to merge 1 commit into
earendil-works:mainfrom
darrendc26:fix-error-body-fallback
Closed

fix: Preserve raw HTTP error status and bodies for non-schema errors#5820
darrendc26 wants to merge 1 commit into
earendil-works:mainfrom
darrendc26:fix-error-body-fallback

Conversation

@darrendc26

Copy link
Copy Markdown

closes #5763

Summary

When an endpoint behind a proxy/gateway returns a non-2xx response with a body that cannot be parsed into standard SDK schemas, most providers swallow the body. This PR introduces a shared error-formatting helper to extract and surface the HTTP status and raw body from various SDK error objects instead of dropping them or returning generic errors.

Changes

  • Shared Utility: Created formatProviderError in packages/ai/src/providers/error-utils.ts to inspect errors for properties like status, statusCode, $response, body, and .error, and parse stringified JSON messages (common in Google SDK errors).
  • Providers: Integrated the helper in the catch blocks of:
    • amazon-bedrock.ts
    • openai-completions.ts
    • openai-responses.ts
    • azure-openai-responses.ts
    • openai-codex-responses.ts
    • google.ts
    • google-vertex.ts
    • mistral.ts
    • anthropic.ts
  • Tests: Added unit tests in packages/ai/test/error-utils.test.ts to verify extraction and formatting logic across different mock provider error structures.

@github-actions

Copy link
Copy Markdown
Contributor

This PR was auto-closed. Only contributors approved with lgtm can open PRs. Open an issue first.

Maintainers review auto-closed issues daily. Issues that do not meet the quality bar in CONTRIBUTING.md will not be reopened or receive a reply.

If a maintainer replies lgtmi, your future issues will stay open. If a maintainer replies lgtm, your future issues and PRs will stay open.

See CONTRIBUTING.md.

@github-actions github-actions Bot closed this Jun 16, 2026
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.

Providers swallow the HTTP error body, so gateway / non-schema errors are unreadable

1 participant