Introduction
This guide covers all possible response codes, error formats, and best practices for handling errors when integrating with the Lovi API.π HTTP Status Codes
Successful Responses
200 OK - Request Successful
Notification Processed:Client Error Responses (4xx)
400 Bad Request - Invalid Parameters
Missing Required Field:401 Unauthorized - Authentication Failed
Invalid Access Key:403 Forbidden - Access Denied
Insufficient Permissions:404 Not Found - Resource Not Found
Template Not Found:422 Unprocessable Entity - Business Logic Error
Template Not Approved:429 Too Many Requests - Rate Limit Exceeded
Rate Limit Hit:Server Error Responses (5xx)
500 Internal Server Error
General Server Error:502 Bad Gateway
Upstream Service Error:503 Service Unavailable
Maintenance Mode:π Retry Strategies
Recommended Retry Logic
| Status Code | Action | Retry Strategy |
|---|---|---|
400, 404, 422 | β Donβt retry | Fix request and try again |
401, 403 | β Donβt retry | Refresh authentication |
429 | β° Retry with backoff | Use retry_after header |
500, 502, 503 | π Retry with exponential backoff | Max 3 attempts |
Implementation Example
π Best Practices
Error Logging
Always log these fields:Error Handling Checklist
β Pre-request Validation- Validate phone number format
- Check required fields
- Validate datetime format
- Verify template exists
- Log all API requests
- Include request_id in logs
- Monitor response times
- Track error rates
- Implement appropriate retry logic
- Cache authentication tokens
- Handle rate limits gracefully
- Provide meaningful error messages to users
- Show user-friendly error messages
- Provide actionable feedback
- Donβt expose internal error details
- Offer alternatives when possible
Monitoring & Alerting
Key Metrics to Monitor:- Error rate per endpoint
- Average response time
- Rate limit hits
- Authentication failures
- Template not found errors
- Error rate > 5%
- Response time > 2 seconds
- Rate limit hits > 10/hour
- Authentication failures > 20/hour
π οΈ Development Tools
Error Testing
Test different error scenarios:Error Response Parser
π¨ Common Issues & Solutions
Authentication Issues
Problem:Invalid or expired access key
Solution:
- Check if access_key is in URL parameters
- Verify the key hasnβt been revoked
- Ensure youβre using the correct company key
Template Issues
Problem:Template not found
Solutions:
- Verify template name spelling
- Check template language matches
- Ensure template is approved
- Use GET /templates to list available templates
Rate Limiting
Problem:Too many requests
Solutions:
- Implement exponential backoff
- Respect retry_after headers
- Batch requests when possible
- Monitor usage patterns
Data Validation
Problem:Validation failed
Solutions:
- Validate data before sending
- Use proper phone number format
- Check datetime format
- Verify required fields are present
request_id when contacting support for faster resolution of issues.