Errors

What the SDK throws, and how to handle it.

Failures from the SDK's own code are Error objects with a descriptive message. Failures from the API are thrown by the generated client as APIError.

Messages you can match on

Message Where What to do
Account not deployed on chain <id> account.address The account has no contract on that chain yet. Use the right chain or wait for deployment.
Smart custody account not deployed on chain <id> prepareDeposit, prepareTradeQuote, prepareBorrowQuote Same cause.
Order <id> has already been completed TradeQuoteClient.from…Id The quote was already executed. Load the result instead of executing again.
Order <id> is not a purchase order / …is not a sell order fromOrderId, fromSellOrderId You used the wrong builder for that order.
Transaction reverted: <hash> DepositClient.submit The transfer failed on chain.
Failed to initialize viem chain configuration any call that reads the chain The viem option was missing or invalid.

API errors

The generated client throws an APIError for non-2xx responses, with status, code (an ErrCode value) and message. Test for it with isAPIError(error), and use code to decide what to do.

Code Meaning Retry?
invalid_argument The request was malformed or rejected by validation, for example a bad handle. No. Fix the input.
permission_denied A bad or missing API key. No.
already_exists A name or handle is taken. No.
not_found The id does not exist. No.
resource_exhausted A limit was hit. No, until something changes.
unavailable, internal A temporary server problem. Yes, with backoff.
try {
  await quote.execute()
} catch (error) {
  if (isAPIError(error) && error.code === ErrCode.Unavailable) {
    // retry after a delay
  } else {
    throw error
  }
}

Retrying execute()

execute() submits a transaction, so retrying it blindly after a network timeout can submit twice. The SDK refuses to execute an order that is already completed. After a timeout, load the order by id and check its status before retrying.