Skip to Content

Errors

import { SendAfricaError, SendAfricaNetworkError, } from 'sendafrica' try { await client.sms.send({ to: '999', message: 'test' }) } catch (err) { if (err instanceof SendAfricaError) { console.log(err.code, err.message, err.requestId, err.httpStatus) if (err.isInsufficientCredits) { /* 402 */ } if (err.isRateLimited) { /* 429 */ } if (err.isUnauthorized) { /* 401 */ } } else if (err instanceof SendAfricaNetworkError) { console.error('network failure or timeout', err.cause) } }
ErrorThrownProperties
SendAfricaErrorAny API error (success: false)code, message, requestId, httpStatus; helpers isInsufficientCredits, isRateLimited, isUnauthorized
SendAfricaNetworkErrorTimeouts, DNS/connection failures, non-JSON responsescause (original error)
InvalidPhoneNumberErrorPhone helpers on an invalid Tanzania numbermessage

Practical guidance

  • Send-safe retries. Combine idempotencyKey with your retry logic so transient failures never double-send.
  • Let the retry layer eat transient failures. 429/5xx and network errors retry automatically up to maxRetries (default 2).
  • Log requestId. Include it in support tickets so the API team can trace the request.
  • Catch the base class first. SendAfricaError covers all API errors; SendAfricaNetworkError is separate because the failure never reached the API.
Last updated on