Skip to Content

Errors

All SDK errors inherit from SendAfricaError, so a broad catch is always safe:

from sendafrica import SendAfricaError try: client.sms.send(to="invalid", message="test") except SendAfricaError as e: print(e.status_code, e.request_id, e.message)

Exception taxonomy

ExceptionHTTPMeaning
AuthenticationError401Missing or invalid API key
ValidationError400/422Bad payload, missing fields
InvalidPhoneErrorFails phone validation before network call
InsufficientCreditsError402Not enough SMS credits
RateLimitError429Rate limited; has retry_after attribute
NotFoundError404Resource does not exist
ServerError5xxTransient API failure
APIConnectionErrorNetwork failure or timeout (requests transport)
WebhookSignatureErrorSignature verification failed

Every exception carries .status_code, .request_id, and .message (available on all; .status_code is None for local transport errors).

Practical guidance

  • Catch specific errors for specific flows. Handle InsufficientCreditsError by prompting a top-up; handle RateLimitError by honoring e.retry_after.
  • Let the retry layer eat transient failures. The transport retries 429/5xx automatically — see Authentication for max_retries.
  • Log request_id. Include it in support tickets so the API team can trace the request.
Last updated on