Skip to content

fix: translate resource-call errors into ApiError - #18

Merged
bufo24 merged 1 commit into
mainfrom
fix/translate-resource-errors
Jul 7, 2026
Merged

fix: translate resource-call errors into ApiError#18
bufo24 merged 1 commit into
mainfrom
fix/translate-resource-errors

Conversation

@bufo24

@bufo24 bufo24 commented Jul 7, 2026

Copy link
Copy Markdown
Member

Problem

The payments README documents that resource calls throw the SDK's typed errors:

try {
  await payments.wallets.list({ environmentId });
} catch (err) {
  if (err instanceof ApiError) { ... }
}

But Environments, Wallets, and Transactions call the generated client via getSdk(graphqlClient) directly, bypassing AmbossClient.gqlRequest (which is where translateError runs). So these calls actually throw raw graphql-request ClientErrors — err instanceof ApiError is always false, and the documented error contract is broken.

Fix

Added translateSdkErrors, an SdkFunctionWrapper that runs AmbossClient.translateError on any thrown error, and passed it to every getSdk(...) call. Translation happens once, at the generated-client boundary, so all current and future resource methods are covered.

this.#sdk = getSdk(graphqlClient, translateSdkErrors);

Tests

Added sdkErrors.test.ts: a resource call whose fetch returns a GraphQL error now rejects with ApiError (message preserved), not a raw ClientError.

Verified: typecheck ✓, build ✓, format ✓, 28/28 payments tests ✓.

Note

Touches packages/payments, so this cuts the next release — @ambosstech/payments@0.1.1 (its first published bump) — which is what exercises the corrected publish pipeline.

Resource calls (environments/wallets/transactions) use the generated SDK
client directly rather than AmbossClient.gqlRequest, so raw graphql-request
ClientErrors escaped untranslated — contradicting the documented contract
that these calls throw ApiError/NetworkError. Pass a translating
SdkFunctionWrapper to every getSdk call so errors are converted at the
single generated-client boundary.
@bufo24
bufo24 merged commit 82407cc into main Jul 7, 2026
2 checks passed
@apotdevin apotdevin mentioned this pull request Jul 7, 2026
@bufo24
bufo24 deleted the fix/translate-resource-errors branch July 7, 2026 10:41
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