Skip to content

Make isSignerApproved throw on errors - #2012

Open
tomas-martins-crossmint wants to merge 2 commits into
mainfrom
tomas/wal-11425-make-issignerapproved-throw-on-errors-in-the-ts-sdk
Open

Make isSignerApproved throw on errors#2012
tomas-martins-crossmint wants to merge 2 commits into
mainfrom
tomas/wal-11425-make-issignerapproved-throw-on-errors-in-the-ts-sdk

Conversation

@tomas-martins-crossmint

@tomas-martins-crossmint tomas-martins-crossmint commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

wallet.isSignerApproved swallowed every error and resolved to false, so callers couldn't tell a signer that isn't approved from a request that failed. It now throws on real failures and keeps resolving false for a signer that isn't registered, matching Swift (#128) and Kotlin (#131).

Changes

  • ApiClient.getSigner now throws an ApiClientError carrying the HTTP status on non-ok responses, instead of returning the error body as a regular result
  • SignerManager.isSignerApproved maps a 404 to false (the signer isn't registered) and lets every other error bubble up to the caller
  • getSignerState keeps its lenient null-state fallback, since assemble and the recovery flow rely on it to degrade gracefully
  • Added getSigner tests for the ok and non-ok paths, and isSignerApproved tests for the approved, not registered, and failure cases

@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7e78d25

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@crossmint/wallets-sdk Patch
@crossmint/wallets-quickstart-devkit Patch
@crossmint/wallets-playground-react Patch
@crossmint/client-sdk-react-base Patch
@crossmint/client-sdk-react-native-ui Patch
@crossmint/client-sdk-react-ui Patch
@crossmint/wallets-playground-expo Patch
@crossmint/auth-ssr-nextjs-demo Patch
@crossmint/client-sdk-nextjs-starter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@greptile-apps

greptile-apps Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
### Issue 1
packages/wallets/src/wallets/services/signer-manager.ts:226-227
**Validate required signer fields**

The new validation rejects every response containing an `error` property before checking whether valid signer data is also present. Validate the fields required by `mapApiSignerToSigner` instead, so error metadata accompanying usable signer data does not make `isSignerApproved()` throw.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "Make isSignerApproved throw when the sig..." | Re-trigger Greptile

Comment on lines +226 to +227
if (signerResponse == null || typeof signerResponse !== "object" || "error" in signerResponse) {
throw new Error(`Failed to fetch the approval state of signer ${signerLocator}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Validate required signer fields

The new validation rejects every response containing an error property before checking whether valid signer data is also present. Validate the fields required by mapApiSignerToSigner instead, so error metadata accompanying usable signer data does not make isSignerApproved() throw.

Rule Used: When validating API response structures, avoid che... (source)

Learned From
Paella-Labs/crossbit-main#21001

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/wallets/src/wallets/services/signer-manager.ts
Line: 226-227

Comment:
**Validate required signer fields**

The new validation rejects every response containing an `error` property before checking whether valid signer data is also present. Validate the fields required by `mapApiSignerToSigner` instead, so error metadata accompanying usable signer data does not make `isSignerApproved()` throw.

**Rule Used:** When validating API response structures, avoid che... ([source](https://app.greptile.com/crossmint/-/custom-context?memory=11da8f5d-8c7c-4a66-8d65-236276bfb2e5))

**Learned From**
[Paella-Labs/crossbit-main#21001](https://github.com/Paella-Labs/crossbit-main/pull/21001)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the success DTO for this endpoint is a union of signer shapes with no error field, so a body carrying error metadata next to usable signer data isn't something the API can return. Error bodies only come with non-2xx statuses, and those now throw in getSigner before this check runs. Keeping the "error" in response narrowing also matches how the rest of the package guards responses (getSignerState, send, etc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair point — since getSigner now throws on non-2xx responses before #fetchSigner ever sees the body, an error payload can't coexist with valid signer data by the time this check runs. And the consistency with getSignerState, send, and the rest of the package is a good reason to keep the pattern uniform. I'll withdraw the concern.

Shall I remember this as a rule: "trust "error" in response narrowing as a valid response guard in this package, consistent with getSignerState, send, and other callers, since non-2xx bodies are thrown before reaching these checks"?

@tomas-martins-crossmint
tomas-martins-crossmint force-pushed the tomas/wal-11425-make-issignerapproved-throw-on-errors-in-the-ts-sdk branch from 771b036 to 7e78d25 Compare August 7, 2026 12:31
@greptile-apps

greptile-apps Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "Make isSignerApproved throw when the sig..." | Re-trigger Greptile

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