Skip to main content

Error Handling

Lineserve APIs return standard HTTP status codes along with detailed error messages.

Common Error Codesโ€‹

CodeDescription
400Bad Request - Invalid parameters
401Unauthorized - Missing or invalid API key
403Forbidden - Insufficient permissions
404Not Found - Resource doesn't exist
429Too Many Requests - Rate limit exceeded
500Server 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