Skip to main content

Error Handling

When an API request fails, the response body contains an error object with a machine-readable code and a human-readable message.

Error Response Format

{
"error": {
"code": "ERROR_CODE",
"message": "Human readable description of the error"
}
}

Error Codes

Error CodeHTTP StatusDescription
UNAUTHORIZED401The API key is missing, invalid, or has been revoked.
INVALID_REQUEST400The request is malformed or contains invalid parameters. Check the message field for details.
NOT_FOUND404The requested resource does not exist.
RATE_LIMITED429You have exceeded the rate limit. Wait and retry after the period indicated in the response headers.
INTERNAL_ERROR500An unexpected error occurred on the server. If this persists, contact support.

HTTP Status Codes

The API uses standard HTTP status codes:

Status CodeMeaning
200Success. The request completed successfully.
400Bad Request. The request was invalid.
401Unauthorized. Authentication failed.
404Not Found. The resource does not exist.
429Too Many Requests. Rate limit exceeded.
500Internal Server Error. Something went wrong on our end.

Error Response Examples

Missing API Key

curl -X GET "https://api.convotic.com/v1/info"
{
"error": {
"code": "UNAUTHORIZED",
"message": "Missing X-API-Key header"
}
}

Invalid Parameter

curl -X GET "https://api.convotic.com/v1/contacts?limit=500" \
-H "X-API-Key: your-api-key-here"
{
"error": {
"code": "INVALID_REQUEST",
"message": "Parameter 'limit' must be between 1 and 100"
}
}

Resource Not Found

{
"error": {
"code": "NOT_FOUND",
"message": "Conversation 'conv_invalid' not found"
}
}

Rate Limited

{
"error": {
"code": "RATE_LIMITED",
"message": "Rate limit exceeded. Retry after 12 seconds."
}
}

Handling Errors in TypeScript

interface ApiError {
error: {
code: string;
message: string;
};
}

async function apiRequest(path: string): Promise<any> {
const response = await fetch(`https://api.convotic.com/v1${path}`, {
headers: {
"X-API-Key": "your-api-key-here",
},
});

if (!response.ok) {
const body: ApiError = await response.json();
switch (body.error.code) {
case "RATE_LIMITED":
// Wait and retry
console.warn("Rate limited, retrying...");
break;
case "UNAUTHORIZED":
// Check API key
throw new Error("Invalid API key");
default:
throw new Error(`API error: ${body.error.message}`);
}
}

return response.json();
}