Skip to main content
The SDK throws typed errors you can catch and handle specifically.

Error Classes

import {
  SdkError,          // Base class
  ValidationError,   // Invalid input parameters
  AuthError,         // Missing API key or wallet/signer
  NetworkError,      // HTTP failures, timeouts, server errors
  SigningError,      // Wallet signing failed or rejected
  NotSupportedError, // Operation not supported (e.g., Kalshi limit orders)
} from '@predexon/trade-sdk';
All errors have a code property:
ErrorCodeWhen
ValidationErrorVALIDATION_ERRORInvalid params, wrong amount/size combo, price out of range
AuthErrorAUTH_ERRORMissing API key, missing wallet/signer in SDK config
NetworkErrorNETWORK_ERRORHTTP errors, timeouts, server errors, 409 conflicts
SigningErrorSIGNING_ERRORWallet rejected signature, missing signing method
NotSupportedErrorNOT_SUPPORTEDOperation unavailable for venue (e.g., Kalshi limit orders)

Handling Errors

try {
  await sdk.placeOrder({
    core: { venue: 'polymarket', wallet: '0x...', side: 'buy', amount: '10', type: 'market' },
    flags: { tokenId: '12345...' },
  });
} catch (error) {
  if (error instanceof ValidationError) {
    // Fix input and retry
  } else if (error instanceof SigningError) {
    // User rejected or wallet missing method
  } else if (error instanceof AuthError) {
    // Missing API key or wallet config
  } else if (error instanceof NetworkError) {
    // Safe to retry (use idempotency key)
  } else if (error instanceof NotSupportedError) {
    // Operation not available for this venue/wallet
  }
}

Retryable vs Non-Retryable

ErrorRetryable?Action
NetworkErrorYesRetry with same idempotency key
ValidationErrorNoFix input parameters
AuthErrorNoFix API key or wallet setup
SigningErrorNoUser must approve signature
NotSupportedErrorNoOperation not available

Error Cause

Errors preserve the original cause for debugging:
catch (error) {
  if (error instanceof SigningError) {
    console.log(error.message);  // "Wallet signing failed"
    console.log(error.cause);    // Original error from wallet
  }
}

Next Steps