fix: prevent [object Object] in API error messages - #234
Merged
Conversation
- Handle nested `{ error: { message } }` error shape in auth resources
(both CLI and SDK implementations) by replacing the cast-only
`err?.error` interpolation with `extractOAuthErrorMessage`, which
does a runtime typeof check before descending into the object
- Fix `switch (err.error)` in `pollDeviceAuth` to switch on
`extractOAuthErrorCode(err)` so polling continues correctly when a
non-string error arrives (object would never match a string case)
- Fix `error_description` truthy guard to a nullish check so an empty
string from the server is preserved rather than falling back to the
error code
- Replace inline cast-only error extraction in payment-methods,
shipping-address, user-info, and web-bot-auth resources with
`extractErrorMessage` from base.ts, which already handles both
string and nested-object error shapes
- Replace `String(err)` in `useAsyncAction` with `JSON.stringify(err)`
so thrown plain objects produce readable output instead of
[object Object]
- Add tests covering all of the above
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
kreese-stripe
approved these changes
Aug 6, 2026
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.
Problem
When the API returns an error in the nested object shape { "error": { "message": "invalid scope: something" } }, several places in the codebase would coerce that object directly into a string — producing [object Object] in the terminal instead of the actual error message.
1 Example:
Before:
After:
Root causes fixed
the message.
continuing. Fixed by switching on extractOAuthErrorCode(err) (returns string | undefined).
match the prior ?? behavior.
coerced. Fixed by replacing the inline pattern with extractErrorMessage(data, rawBody) from base.ts, which already handles both shapes correctly.