Skip to content

ApiError surfaces the decoded response body as its message for non-JSON / non-conforming error bodies#189

Draft
parthban-db wants to merge 1 commit into
mainfrom
parthban-db/stack/bugbash-bug3-error-bodies
Draft

ApiError surfaces the decoded response body as its message for non-JSON / non-conforming error bodies#189
parthban-db wants to merge 1 commit into
mainfrom
parthban-db/stack/bugbash-bug3-error-bodies

Conversation

@parthban-db

@parthban-db parthban-db commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🥞 Stacked PR

Use this link to review incremental changes.


Summary

ApiError now surfaces the decoded response body as its message when the error body is not valid JSON or fails schema validation, instead of leaving the message empty.

Why

Today a non-JSON error response (proxy HTML, binary bodies) or a JSON body that does not match the error schema produces an ApiError with an empty message, so the failure is opaque — the only signal a caller gets is the HTTP status. Surfacing the decoded body makes such failures debuggable.

What changed

  • fromHttpError decodes the response body once and uses that decoded string as the message in both fallback paths (the JSON.parse throws path and the schema-validation-fails path), instead of ''.
  • code (still Code.UNKNOWN in these paths), the empty-body branch, and the verbatim error_code mapping are unchanged.
  • Surfacing the decoded body as the message is a small divergence from the Go SDK's apierr.APIError, which leaves it empty.

How is this tested?

apierror.test.ts asserts the decoded body becomes the message for an HTML body and a malformed-JSON body. npm run build, npm run lint, npm run typecheck, and npm test --workspace @databricks/sdk-core all pass.

@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug3-error-bodies branch from 6ef1457 to 259ed70 Compare June 4, 2026 11:02
@parthban-db parthban-db changed the base branch from main to parthban-db/stack/bugbash-bug2-apierror-code June 4, 2026 11:02
@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug2-apierror-code branch from 8671804 to 357b416 Compare June 4, 2026 13:02
@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug3-error-bodies branch from 259ed70 to 10e022f Compare June 4, 2026 13:02
@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug2-apierror-code branch from 4cb8f6f to 736f638 Compare June 7, 2026 15:26
@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug3-error-bodies branch from 10e022f to 4531f6c Compare June 7, 2026 15:26
@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug2-apierror-code branch from 736f638 to 8a48fef Compare June 8, 2026 11:56
@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug3-error-bodies branch 2 times, most recently from 0aa7d3a to 49678e2 Compare June 8, 2026 16:07
@parthban-db parthban-db changed the base branch from parthban-db/stack/bugbash-bug2-apierror-code to main June 8, 2026 16:08
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Please ensure that the NEXT_CHANGELOG.md file is updated with any relevant changes.
If this is not necessary for your PR, please include the following in your PR description:
NO_CHANGELOG=true
and rerun the job.

…ON / non-conforming error bodies

Today a non-JSON error response (proxy HTML, binary bodies) or one that fails schema validation yields an empty ApiError message, so the failure is opaque. fromHttpError now decodes the body once and uses that decoded string as the message in both fallback paths (JSON.parse throws; schema validation fails) instead of an empty string. The code, the empty-body branch, and the verbatim error_code mapping are unchanged.

This is a hand-written core change only; no generator change is needed. Note: surfacing the decoded body as the message is a small divergence from the Go SDK's apierr.APIError, which leaves it empty.

Co-authored-by: Isaac
@parthban-db parthban-db force-pushed the parthban-db/stack/bugbash-bug3-error-bodies branch from 49678e2 to c756199 Compare June 10, 2026 10:23
@parthban-db parthban-db changed the title Make API errors debuggable: preserve error-like values, decode body, attach request context ApiError surfaces the decoded response body as its message for non-JSON / non-conforming error bodies Jun 10, 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.

1 participant