Skip to main content

Response Codes & Error Handling

Response Format

All API responses follow a consistent format with a success flag and relevant data or error information.

{
"success": true,
"data": {
// Response data specific to the endpoint
}
}

HTTP Status Codes

Our API uses standard HTTP status codes to indicate the success or failure of requests.

Success Codes

Status CodeDescriptionExample Scenario
200OKSuccessfully retrieved recipe
201CreatedSuccessfully created new recipe

Client Error Codes

Status CodeDescriptionExample Scenario
400Bad RequestInvalid input parameters
401UnauthorizedMissing or invalid API key
403ForbiddenValid API key but insufficient permissions
404Not FoundRecipe or job not found
429Too Many RequestsRate limit exceeded

Server Error Codes

Status CodeDescriptionExample Scenario
500Internal Server ErrorUnexpected server error
503Service UnavailableServer maintenance

Common Error Types

Authentication Errors

{
"success": false,
"message": "Invalid API key",
"statusCode": 401
}

Common authentication errors:

  • "Invalid API key"
  • "API key is required"
  • "API key has expired"

Rate Limiting

{
"success": false,
"message": "Rate limit exceeded. Please try again later",
"statusCode": 429,
"retryAfter": 60
}

Rate limiting responses include:

  • Current rate limit status
  • Time until limit resets
  • Recommended retry delay

Resource Errors

{
"success": false,
"message": "Recipe not found: rec_123",
"statusCode": 404
}

Common resource errors:

  • "Recipe not found"
  • "Job not found"
  • "Invalid recipe configuration"

Validation Errors

{
"success": false,
"message": "Invalid input parameters",
"statusCode": 400,
"errors": [
{
"field": "url",
"message": "Invalid URL format"
}
]
}

Common validation errors:

  • "Invalid input parameters"
  • "Required field missing"
  • "Value out of allowed range"

Error Handling Best Practices

1. Check Success Flag

Always check the success field first:

if (!response.success) {
handleError(response);
return;
}

2. Handle Rate Limits

Implement exponential backoff:

async function fetchWithRetry(url, options, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
const response = await fetch(url, options);
const data = await response.json();

if (response.status === 429) {
const delay = Math.pow(2, i) * 1000;
await new Promise(resolve => setTimeout(resolve, delay));
continue;
}

return data;
} catch (error) {
if (i === maxRetries - 1) throw error;
}
}
}

3. Validate Input

Validate parameters before making API calls:

function validateRecipe(recipe) {
if (!recipe.url) {
throw new Error("URL is required");
}

if (!recipe.listSelector) {
throw new Error("List selector is required");
}

// Additional validation...
}

4. Complete Error Handler

Example of a comprehensive error handler:

function handleApiError(error) {
switch (error.statusCode) {
case 401:
console.error('Authentication failed:', error.message);
// Refresh token or redirect to login
break;

case 429:
console.error('Rate limit exceeded:', error.message);
// Implement retry logic with backoff
break;

case 404:
console.error('Resource not found:', error.message);
// Show user-friendly error message
break;

default:
console.error('API error:', error.message);
// Generic error handling
}
}