Overview
Proper error handling is crucial for building robust SMS applications. This guide covers all error types, status codes, and best practices for handling failures gracefully.HTTP Status Codes
The Lamah SMS API uses standard HTTP status codes to indicate the success or failure of requests:| Status Code | Description | Action Required |
|---|---|---|
200 | Success | Continue normal operation |
400 | Bad Request | Fix request parameters |
401 | Unauthorized | Check API token |
402 | Payment Required | Add funds or upgrade plan |
403 | Forbidden | Check permissions |
404 | Not Found | Verify resource exists |
429 | Too Many Requests | Implement rate limiting |
500 | Internal Server Error | Retry request |
Error Response Format
All error responses follow a consistent JSON format:Common Error Codes
Authentication Errors
UNAUTHORIZED - Invalid API Token
UNAUTHORIZED - Invalid API Token
ACCESS_DENIED - Insufficient Permissions
ACCESS_DENIED - Insufficient Permissions
- Token doesn’t have required permissions
- Accessing resources from different project
- Use correct project token
- Contact support for permission issues
Validation Errors
INVALID_PHONE - Invalid Phone Number
INVALID_PHONE - Invalid Phone Number
- Use international format with country code
- Example:
00218912345678 - Validate numbers before sending
MESSAGE_TOO_LONG - Message Exceeds Limit
MESSAGE_TOO_LONG - Message Exceeds Limit
- Trim message to fit limits
- Split into multiple messages
- Use templates for consistent formatting
Payment Errors
INSUFFICIENT_BALANCE - Low Account Balance
INSUFFICIENT_BALANCE - Low Account Balance
- Add funds to your account
- Enable auto-recharge
- Switch to subscription plan
PAYMENT_METHOD_FAILED - Payment Issue
PAYMENT_METHOD_FAILED - Payment Issue
- Update payment method
- Contact your bank
- Try alternative payment method
Rate Limiting Errors
RATE_LIMIT_EXCEEDED - Too Many Requests
RATE_LIMIT_EXCEEDED - Too Many Requests
- Implement exponential backoff
- Reduce request frequency
- Use bulk endpoints for multiple messages
Error Handling Strategies
Basic Error Handling
Advanced Error Handling with Retry Logic
Error Monitoring and Alerting
Logging Errors
Best Practices
Graceful Degradation
Handle errors gracefully without breaking user experience
Retry Logic
Implement exponential backoff for transient errors
Error Monitoring
Monitor error rates and set up alerts
User Feedback
Provide meaningful error messages to users
Error Recovery Strategies
- Immediate Retry: For network timeouts
- Exponential Backoff: For rate limiting
- Circuit Breaker: For persistent failures
- Fallback Options: Alternative communication methods
- User Notification: Inform users of delivery issues