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
| Exception | HTTP | Meaning |
|---|---|---|
AuthenticationError | 401 | Missing or invalid API key |
ValidationError | 400/422 | Bad payload, missing fields |
InvalidPhoneError | — | Fails phone validation before network call |
InsufficientCreditsError | 402 | Not enough SMS credits |
RateLimitError | 429 | Rate limited; has retry_after attribute |
NotFoundError | 404 | Resource does not exist |
ServerError | 5xx | Transient API failure |
APIConnectionError | — | Network failure or timeout (requests transport) |
WebhookSignatureError | — | Signature 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
InsufficientCreditsErrorby prompting a top-up; handleRateLimitErrorby honoringe.retry_after. - Let the retry layer eat transient failures. The transport retries
429/5xxautomatically — see Authentication formax_retries. - Log
request_id. Include it in support tickets so the API team can trace the request.
Last updated on