Error Response Format
When an error occurs, Vellosim API returns a JSON response with error details:Common Error Codes
Authentication Errors
| Error Code | Status | Description | Solution |
|---|---|---|---|
| UNAUTHORIZED | 401 | Missing or invalid API key | Check your API key and ensure it’s included in the Authorization header |
| FORBIDDEN | 403 | Valid key but insufficient permissions | Contact support to upgrade your permissions |
| RATE_LIMIT_EXCEEDED | 429 | Too many requests | Implement rate limiting and retry with exponential backoff |
Validation Errors
| Error Code | Status | Description | Solution |
|---|---|---|---|
| INVALID_PARAMETERS | 400 | Missing or invalid request parameters | Review the required parameters for the endpoint |
| INVALID_REGION_CODE | 400 | Invalid region code provided | Use valid region codes from the regions endpoint |
| INVALID_PACKAGE_CODE | 400 | Package code doesn’t exist | Verify package code from packages endpoint |
Business Logic Errors
| Error Code | Status | Description | Solution |
|---|---|---|---|
| INSUFFICIENT_BALANCE | 400 | Wallet balance too low | Top up your wallet balance |
| PACKAGE_UNAVAILABLE | 400 | Package is temporarily unavailable | Try a different package or retry later |
| ORDER_NOT_FOUND | 404 | Order ID doesn’t exist | Verify the order ID |
| DUPLICATE_ORDER | 409 | Order already exists | Check your order history |
Server Errors
| Error Code | Status | Description | Solution |
|---|---|---|---|
| INTERNAL_ERROR | 500 | Internal server error | Retry the request or contact support |
| SERVICE_UNAVAILABLE | 503 | Service temporarily unavailable | Wait and retry with exponential backoff |
Error Handling Examples
Basic Error Handling
Advanced Error Handling with Retry Logic
User-Friendly Error Messages
Create a mapping for user-friendly error messages:Validation Before API Calls
Validate data before making API requests to reduce errors:Logging and Monitoring
Implement proper logging for debugging:Best Practices
Implement Exponential Backoff
Implement Exponential Backoff
For transient errors and rate limits, use exponential backoff to automatically retry failed requests with increasing delays.
Don't Retry Client Errors
Don't Retry Client Errors
Never retry 4xx errors (except 429) as they indicate client-side issues that won’t be resolved by retrying.
Log Errors Properly
Log Errors Properly
Log all errors with context to help debugging. Include request parameters, timestamps, and user identifiers (without sensitive data).
Show User-Friendly Messages
Show User-Friendly Messages
Don’t expose technical error messages to end users. Create friendly, actionable error messages instead.
Monitor Error Rates
Monitor Error Rates
Track error rates and patterns to identify issues early and improve your integration.
Graceful Degradation
Graceful Degradation
When APIs fail, provide fallback options or cached data when possible to maintain user experience.
