Skip to content

Errors

The SDK throws errors. It does not return V2-style [error, value] tuples.

import {
  AmountOutOfRangeError,
  DepositRevertedError,
  DepositSimulationError,
  HttpError,
  MaintenanceModeError,
  RefundNotAllowedError,
  RefundRevertedError,
} from '@silentswap/sdk';
 
export function describeSilentSwapError(error: unknown): string {
  if (error instanceof MaintenanceModeError) return error.message;
  if (error instanceof AmountOutOfRangeError) {
    return `${error.code}: ${error.limitAmount ?? 'unknown limit'}`;
  }
  if (error instanceof DepositSimulationError) return error.message;
  if (error instanceof DepositRevertedError) return `Reverted: ${error.depositTxHash}`;
  if (error instanceof RefundNotAllowedError) return error.message;
  if (error instanceof RefundRevertedError) return `Reverted: ${error.refundTxHash}`;
  if (error instanceof HttpError) return `HTTP ${error.status}`;
  return error instanceof Error ? error.message : 'Unknown SilentSwap error';
}

A DepositSimulationError means no transaction was sent. DepositRevertedError and RefundRevertedError preserve hashes for explorer links. HttpError.body carries the API error payload.

Detect wallet user rejection separately from protocol failures so a cancelled signature is not reported as an API incident.