Error Handling
Lineserve APIs return standard HTTP status codes along with detailed error messages.
Common Error Codesโ
Code | Description |
---|---|
400 | Bad Request - Invalid parameters |
401 | Unauthorized - Missing or invalid API key |
403 | Forbidden - Insufficient permissions |
404 | Not Found - Resource doesn't exist |
429 | Too Many Requests - Rate limit exceeded |
500 | Server Error - Internal server issue |
Error Response Formatโ
All errors return JSON with this structure:
{
"error": {
"code": "invalid_parameter",
"message": "The 'to' parameter is required",
"details": {
"parameter": "to",
"documentation_url": "https://docs.lineserve.net/api-reference/error-handling"
}
}
}
Handling Errorsโ
try {
const response = await fetch(apiUrl, options);
if (!response.ok) {
const error = await response.json();
console.error(`API Error: ${error.error.message}`);
// Handle specific error cases
if (error.error.code === 'rate_limited') {
// Implement retry logic
}
}
} catch (error) {
console.error('Network error:', error);
}
Best Practicesโ
- Always check response status codes
- Implement retry logic for rate limits
- Log errors for debugging
- Provide user-friendly messages for common errors