Understanding error responses helps you debug issues quickly. Here are the most common errors you'll encounter.
400 Bad Request
{
"error": "media_id is required"
}
Causes:
Missing required parameter
Invalid parameter format
Malformed JSON
Fix: Check your request body matches the API specification at api.cathopic.com/docs.
401 Unauthorized
{
"message": "Unauthorized"
}
or
{
"error": "Unauthorized token"
}
Causes:
Missing or invalid API key
Deactivated API key
Wrong header name
Fix: Verify your x-api-key header is correct and the key is active in Settings → API.
404 Not Found
{
"error": "No file found for media_id 1234"
}
or
{
"error": "Media item not found"
}
Causes:
Resource doesn't exist
Resource has been deleted
Wrong media_id
Fix: Verify the media_id exists by searching first with /resources.
429 Too Many Requests
{
"error": "Limit exceed."
}
Causes:
Too many requests in short time
Rate limit exceeded
Fix: Implement exponential backoff. Wait and retry with increasing delays (1s, 2s, 4s, etc.).
500 Internal Server Error
{
"error": "Internal server error"
}
Causes:
Temporary server issue
Unexpected condition
Fix: Wait a moment and retry. If it persists, contact support.
Error handling example
async function searchWithErrorHandling(query) {
try {
const response = await fetch('https://api.cathopic.com/resources', {
method: 'POST',
headers: {
'x-api-key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query, page: 1, page_size: 20 })
});
if (!response.ok) {
const error = await response.json();
switch (response.status) {
case 400:
console.error('Bad request:', error);
break;
case 401:
console.error('Unauthorized. Check your API key.');
break;
case 404:
console.error('Resource not found:', error);
break;
case 429:
console.error('Rate limited. Implementing backoff...');
await sleep(5000);
return searchWithErrorHandling(query); // Retry
case 500:
console.error('Server error. Retrying in 10s...');
await sleep(10000);
return searchWithErrorHandling(query);
default:
console.error('Unknown error:', error);
}
throw new Error(`API error: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Request failed:', error);
throw error;
}
}
For persistent errors, check the full API documentation or contact support.