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
Draft
Conversation
6ef1457 to
259ed70
Compare
8671804 to
357b416
Compare
259ed70 to
10e022f
Compare
4cb8f6f to
736f638
Compare
10e022f to
4531f6c
Compare
736f638 to
8a48fef
Compare
0aa7d3a to
49678e2
Compare
|
Please ensure that the NEXT_CHANGELOG.md file is updated with any relevant changes. |
…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
49678e2 to
c756199
Compare
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.
🥞 Stacked PR
Use this link to review incremental changes.
Summary
ApiErrornow surfaces the decoded response body as itsmessagewhen 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
ApiErrorwith an emptymessage, 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
fromHttpErrordecodes the response body once and uses that decoded string as themessagein both fallback paths (theJSON.parsethrows path and the schema-validation-fails path), instead of''.code(stillCode.UNKNOWNin these paths), the empty-body branch, and the verbatimerror_codemapping are unchanged.apierr.APIError, which leaves it empty.How is this tested?
apierror.test.tsasserts the decoded body becomes themessagefor an HTML body and a malformed-JSON body.npm run build,npm run lint,npm run typecheck, andnpm test --workspace @databricks/sdk-coreall pass.