Console →
SDK Reference

Error Handling

The SettleSettle SDK uses typed error classes. Always catch by class — never by message string, because messages can change between versions.

Import the error classes you need#

typescript
import {
  SettleSettleError,        // Base — catch all SDK errors
  InsufficientCreditsError, // 402 — user has no credits
  AuthenticationError,      // 401 — bad or missing API key
  ValidationError,          // 400 — invalid request body
  RateLimitError,           // 429 — too many requests
  TimeoutError,             // 408 — request took too long
  ApiError,                 // Any other API error
} from 'settlesettle'

Full handling example#

typescript
try {
  await settle.wallet.debit('user_123', { amount: 10 })

} catch (err) {

  if (err instanceof InsufficientCreditsError) {
    // Expected — user is out of credits
    // Trigger your paywall or ad fallback
    console.log(`Need: ${err.requestedAmount}, Have: ${err.currentBalance}`)

  } else if (err instanceof AuthenticationError) {
    // Your API key is wrong or missing
    console.error('Check your SETTLESETTLE_API_KEY.')

  } else if (err instanceof ValidationError) {
    // You sent a bad request body
    console.error('Bad request:', err.message, err.fields)

  } else if (err instanceof RateLimitError) {
    // Slow down — too many requests
    console.error(`Rate limited. Retry in ${err.retryAfterMs}ms.`)

  } else if (err instanceof TimeoutError) {
    // Request took too long
    console.error('Request timed out. Check your connection.')

  } else if (err instanceof SettleSettleError) {
    // Any other SDK error — catch-all
    console.error(`SDK error [${err.code}]: ${err.message}`)
    console.error('Status code:', err.statusCode)

  } else {
    // Completely unexpected — rethrow
    throw err
  }
}

Error class reference#

ClassHTTP StatusWhen it's thrownKey properties
SettleSettleErrorAnyBase class — don't throw directlystatusCode, code, payload
AuthenticationError401API key is missing, wrong, or expired
InsufficientCreditsError402Wallet debit with not enough creditsuserId, currentBalance, requestedAmount
ValidationError400Invalid request payloadfields (which fields failed)
RateLimitError429Too many requestsretryAfterMs
TimeoutError408Request exceeded timeout
ApiErrorOtherAny unhandled server errorstatusCode

Errors that are retried automatically by the SDK:#

The SDK automatically retries these before throwing — you only see the error if all retries are exhausted:

  • 429 RateLimitError — respects Retry-After header
  • 5xx server errors
  • Timeouts
  • Network failures

These are never retried (they're deterministic failures):

  • 400 ValidationError
  • 401 AuthenticationError
  • 402 InsufficientCreditsError
  • 403 ForbiddenError