Skip to main content
All SDK errors extend TrussetError and carry a machine-readable code, HTTP statusCode, and the server’s requestId when available. Catch specific subclasses to handle different failure modes.

Error hierarchy

import {
  TrussetError,      // Base class - all errors extend this
  AuthError,         // 401 - invalid or expired API key
  ValidationError,   // 400 - bad input caught client-side
  NetworkError,      // 0   - timeout, DNS failure, connection refused
} from '@trusset/sdk'

Catching errors

try {
  await trusset.customers.manage.get('0xinvalid')
} catch (err) {
  if (err instanceof ValidationError) {
    // Input rejected before hitting the API
    console.error(err.message) // "walletAddress must be a valid Ethereum address"
    return
  }

  if (err instanceof AuthError) {
    // API key is invalid, expired, or the instance is archived
    console.error(err.message, err.requestId)
    return
  }

  if (err instanceof NetworkError) {
    // Request timed out or network is unreachable
    console.error(err.message)
    return
  }

  if (err instanceof TrussetError) {
    // Server returned a non-success response (4xx/5xx)
    console.error(err.code, err.statusCode, err.message, err.requestId)
  }
}

Error properties

Every TrussetError instance exposes:
PropertyTypeDescription
messagestringHuman-readable error description
codestringMachine-readable error code (e.g. NOT_FOUND, RELAYER_FROZEN)
statusCodenumberHTTP status code. 0 for network errors.
requestIdstring | nullServer-assigned request ID for support inquiries

Common error codes

CodeStatusMeaning
AUTH_REQUIRED401No API key provided
AUTH_FAILED401Invalid or expired API key
NOT_FOUND404Resource does not exist
CUSTOMER_EXISTS409Duplicate wallet or externalId
WALLET_IN_USE409Wallet already assigned to another customer
SERVICE_NOT_ENABLED403Required service not enabled on this instance
RELAYER_NOT_CONFIGURED400No relayer wallet set up for this instance
RELAYER_FROZEN403Relayer is frozen - unfreeze in the Issuer Platform
RELAYER_LIMIT_EXCEEDED429Daily transaction limit reached
VALIDATION_ERROR400Client-side input validation failure

Retry behavior

The HTTP layer automatically retries requests that fail with transient errors:
StatusRetried
408 Request TimeoutYes
429 Too Many RequestsYes
500 Internal Server ErrorYes
502 Bad GatewayYes
503 Service UnavailableYes
504 Gateway TimeoutYes
Network errors (DNS, connection)Yes
Timeouts (AbortError)Yes
400, 401, 403, 404, 409No
Retries use exponential backoff: 1s, 2s, 4s, capped at 10s. Configure via maxRetries in the client constructor. Set to 0 to disable.
const trusset = new TrussetClient({
  apiKey: '...',
  maxRetries: 5,   // up to 5 retries
  timeoutMs: 60_000, // 60s timeout per attempt
})

Logging

Pass a logger to surface retry attempts and request metadata during development:
const trusset = new TrussetClient({
  apiKey: '...',
  logger: console,
})
The logger receives debug calls for retry attempts, including the URL and attempt number. No sensitive data (API keys, request bodies) is logged.