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)
}
}| Error | Thrown | Properties |
|---|---|---|
SendAfricaError | Any API error (success: false) | code, message, requestId, httpStatus; helpers isInsufficientCredits, isRateLimited, isUnauthorized |
SendAfricaNetworkError | Timeouts, DNS/connection failures, non-JSON responses | cause (original error) |
InvalidPhoneNumberError | Phone helpers on an invalid Tanzania number | message |
Practical guidance
- Send-safe retries. Combine
idempotencyKeywith your retry logic so transient failures never double-send. - Let the retry layer eat transient failures.
429/5xxand network errors retry automatically up tomaxRetries(default 2). - Log
requestId. Include it in support tickets so the API team can trace the request. - Catch the base class first.
SendAfricaErrorcovers all API errors;SendAfricaNetworkErroris separate because the failure never reached the API.
Last updated on