Skip to main content
The Trustware SDK surfaces errors through a typed TrustwareError class, so you always know what went wrong and why. You can handle errors reactively via the onError callback, imperatively by catching thrown errors in the headless core, or by listening for the error event in the lifecycle events stream.

The TrustwareError class

TrustwareError extends the native Error class with three additional fields: Import it directly from the SDK:

Error codes

The TrustwareErrorCode enum covers all error conditions the SDK can produce.
INVALID_API_KEY is thrown synchronously during initialization. Make sure to handle it at startup rather than only in your per-transaction error handler.

Handling errors via onError

Pass an onError callback in your TrustwareConfigOptions to receive all errors emitted by the widget and provider. This is the simplest approach for most integrations.
If you want to display a user-friendly message instead of a raw technical error, use error.userMessage when it is defined:
In production, log error.code and error.message to your error tracking service and display error.userMessage to users. This gives you diagnostic detail without exposing internal error strings.

Handling errors with try/catch

When using the headless core API, errors are thrown as exceptions. Wrap core calls in a try/catch block.

Errors that are not TrustwareError

Some SDK rejections are thrown as a plain Error with no code property. An instanceof TrustwareError check will not match them and error.code will be undefined, so handle them by message or by name.

Destination posthook validation

Trustware.buildRoute() and Trustware.buildDepositAddress() reject a structurally incomplete hooks.postHook before sending the request. fullAmount and amountInputPos are provider dependent. See dynamic landed-balance mode. These checks confirm the request is complete. They do not verify that your calldata is correct, that target is a contract, or that the destination call will succeed. The API is authoritative for everything the client cannot check, and rejects a posthook it will not route with a 400 and a message describing the problem. See vault destinations.

Source token approvals

Trustware.sendRouteTransaction() can submit ERC-20 approvals before the route transaction. Three failures can surface from that step. All three are recoverable. Let the user retry rather than treating the deposit as failed.
SDKRPCError is not exported from the package, so identify it by error.name rather than with instanceof.

A resolved poll is not a success

Trustware.pollStatus() resolves when the route reaches success, when it reaches failed, and when polling times out. Always branch on the status.

The RateLimitError class

When your integration hits the API rate limit, the SDK surfaces the 429 as a RateLimitError. It extends the native Error class directly (not TrustwareError), so a single instanceof TrustwareError check will not match it; handle it as a separate case.
The rateLimitInfo property has the following shape: