Skip to main content
Failures come in two shapes:
  1. Thrown errors — the SDK throws a typed error (every class extends OneSwapError). These happen at call time (swaps.createSwap, quotes.get, …) — for example a pair with no pool, an already-open swap, an invalid key, or a rate limit.
  2. Terminal statuses — the swap is created successfully but ends in a non-success terminal state (refunded, expired, failed). You read these off the swap’s status, not from a thrown error.
Because swaps are atomic DvP, a swap that does not complete has its input refunded — funds are never stranded by a partial swap.

Typed errors

Every error extends OneSwapError, which carries an optional status (HTTP status code) and data (the parsed response body). Catch by class with instanceof:

Terminal statuses

A created swap always reaches one of these terminal statuses. Read status (and amountOut / senderParty / error) off the swap:

The “already has an open swap” case

Only one open swap per userRef is allowed. When you hit this, don’t create a duplicate — ask for the open swap and act on it. You don’t need to have stored the id: getOpenSwap finds it for you.
cancel only closes a swap still in awaiting_deposit. Once a deposit has arrived the swap holds the user’s funds and must run to completion — cancelling then throws ConflictError (409). Never treat that 409 as a reason to retry createSwap; wait on the existing swap with waitForSwap instead.
Store swap.id against your userRef at creation so you can always find the open swap again.

The “no direct pool” case

Every swap settles against one pool, and there is no multi-hop routing. quotes.get throws NoDirectPoolError when no pool trades the pair — the error tells you both symbols so you can route through an intermediate asset yourself:

Rate limits

Requests beyond a key’s per-minute tier throw RateLimitError (429). Create is the tightest tier; polling and reads are looser. Back off and retry:
Prefer waitForSwap (or a fixed poll interval) over tight polling loops so you stay under the limit.

A robust create-and-wait pattern

If waitForSwap times out while a swap is still non-terminal, the swap may still settle. Resume with getSwap(id) rather than treating it as failed.