Error Handling
The Voicy API uses conventional HTTP status codes to indicate success or failure of requests.Error Response Format
All error responses follow this format:{
"status": "error",
"message": "Description of what went wrong"
}
HTTP Status Codes
Success Codes
| Code | Meaning | When Used |
|---|---|---|
| 200 | OK | Successful GET, POST, PATCH, DELETE requests |
| 201 | Created | Successful resource creation (call-dial) |
Client Error Codes
| Code | Meaning | Common Causes |
|---|---|---|
| 400 | Bad Request | Invalid JSON, missing required fields, invalid phone number format |
| 401 | Unauthorized | Invalid or revoked API key, a key of an archived account, expired token, missing Authorization header |
| 403 | Forbidden | API key doesn’t have access to the requested resource |
| 404 | Not Found | Call ID doesn’t exist or belongs to another account |
| 422 | Unprocessable Entity | Request is valid but cannot be processed |
| 413 | Payload Too Large | The request body is over 1 MiB. Nothing was created or changed; send a smaller body, because retrying the same one fails the same way |
| 429 | Too Many Requests | This API key or its account exceeded a per-minute rate limit. Wait Retry-After seconds, then retry — see Rate Limits |
Server Error Codes
| Code | Meaning | What To Do |
|---|---|---|
| 500 | Internal Server Error | Retry with exponential backoff, contact support if persistent |
| 502 | Bad Gateway | Temporary issue, retry after a few seconds |
| 503 | Service Unavailable | Service is temporarily down, retry later |
Common Errors
// Missing, invalid, revoked or expired credentials (401)
{
"status": "error",
"message": "Invalid or missing authentication"
}
// A malformed field (400)
{
"status": "error",
"message": "Invalid to_number format. Use E.164 (e.g. +15551234567)"
}
// A required field is missing (400)
{
"status": "error",
"message": "to_number is required"
}
// A resource that does not exist, or belongs to another account (404)
{
"status": "error",
"message": "Call not found"
}
// A valid request that refers to something your account does not have (422)
{
"status": "error",
"message": "from_number not found or not accessible"
}
// A read-only key or role trying to change data (403)
{
"status": "error",
"message": "Read-only access: this role cannot modify data"
}
Best Practices
Retry Logic
Retry rate limits (429) after the Retry-After seconds the response gives, and transient server errors (5xx) with exponential backoff:
async function callWithRetry(fn, maxRetries = 3) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
return await fn();
} catch (error) {
const retryable = error.status === 429 || error.status >= 500;
if (retryable && attempt < maxRetries - 1) {
// On a 429, wait what the server says (error.retryAfter = the Retry-After
// header, in seconds); otherwise wait 2^attempt seconds.
const waitMs = error.status === 429 && error.retryAfter
? error.retryAfter * 1000
: 1000 * Math.pow(2, attempt);
await new Promise(r => setTimeout(r, waitMs));
continue;
}
throw error;
}
}
}
Error Logging
Log errors with context for debugging:try {
const call = await createPhoneCall(fromNumber, toNumber);
} catch (error) {
console.error('Failed to create call', {
fromNumber,
toNumber,
status: error.status,
message: error.message,
});
throw error;
}
User-Friendly Messages
Map API errors to user-friendly messages:function getUserMessage(error) {
switch (error.message) {
case 'Invalid phone number format. Use E.164 (e.g. +11234567890)':
return 'Please enter a valid phone number with country code (e.g., +1 555 123 4567)';
case 'Phone number not found or not assigned to your account':
return 'This phone number is not available. Please contact support.';
default:
return 'Something went wrong. Please try again.';
}
}