Skip to main content

Error Types

import { ApiError, AuthError, RateLimitError, NetworkError } from '@sw4p/bridge'
ErrorDescriptionRetryable
AuthErrorInvalid API keyNo
RateLimitErrorToo many requestsYes
ApiErrorGeneral API errorDepends
NetworkErrorConnection failedYes

Handling Examples

try {
  const result = await bridge.transfer(params)
} catch (error) {
  if (error instanceof AuthError) {
    console.error('Invalid API key')
  }
  
  if (error instanceof RateLimitError) {
    await sleep(error.retryAfterMs)
    return retry()
  }
  
  if (error instanceof ApiError) {
    console.error(`API error: ${error.message}`)
  }
}

Retry Strategy

The SDK includes automatic retry with exponential backoff:
const bridge = new Sw4pBridge({
  apiKey: 'sk_...',
  retry: {
    maxAttempts: 3,
    backoffMs: 1000
  }
})