Make API errors debuggable: preserve error-like values, decode body, attach request context#189
Draft
parthban-db wants to merge 1 commit into
Conversation
|
Please ensure that the NEXT_CHANGELOG.md file is updated with any relevant changes. |
6ef1457 to
259ed70
Compare
…attach request context Fixes bug-bash finding #3 in the hand-written core, plus the regenerated SDK output from the paired universe generator PR. toError in packages/core/src/ops/execute.ts now preserves the name and message of error-like objects (those with a string message) instead of collapsing them to Error: [object Object]. ApiError now decodes the response body into its message (so non-JSON, proxy HTML, and binary bodies are visible) and carries the failing request's method and URL: fromHttpError gains optional method/url params, new httpMethod/httpUrl getters expose them, and the message is prefixed with "<method> <url>: ". The generated executeHttpCall and sendAndCheckError call sites thread opts.request.method and opts.request.url through. The regenerated client.ts and utils.ts across all packages come from the paired generator PR in the universe repo and must merge together with it. Note: decoding the body into the message and carrying request context intentionally diverges from the Go SDK's apierr.APIError. Co-authored-by: Isaac
8671804 to
357b416
Compare
259ed70 to
10e022f
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
Makes API errors debuggable:
ApiErrornow decodes the response body into its message and carries the failing request's method and URL, andtoErrorpreserves error-like values instead of collapsing them toError: [object Object]. Pairs with universe PR #2025999, which regenerates the SDK output; the two must merge together.Why
Today a non-JSON or non-conforming error response (proxy HTML, binary bodies) yields an empty
ApiErrormessage, and there is no indication of which request failed, so failures are opaque. This decodes the body so it is visible, prefixes the message with<method> <url>, and stopstoErrorfrom discarding error-like objects that carry a stringmessage.What changed
ApiError.fromHttpErrorgains optionalmethod/urlparams; newhttpMethod/httpUrlgetters expose them and the message is prefixed with"<method> <url>: ".ApiErrorfalls back to the decoded body as its message when the body is not JSON or fails schema validation, instead of an empty string.toError(packages/core/src/ops/execute.ts) keeps thenameandmessageof error-like objects.client.tsandutils.tsacross all generated packages:executeHttpCallthreadsopts.request.method/urlintofromHttpError,parseResponsewraps malformed-body parse failures in a realErrorwith a body snippet, and the client constructor validateshosteagerly.apierr.APIError.Validated: build, typecheck, lint, and
packages/coreunit tests (apierror,execute) pass.