Back to Home
Error Handling
This guide explains how to handle errors when using the RUE API. Understanding and properly handling errors is crucial for building robust applications.
Error Response Format
When an error occurs, the API will return a JSON response with an error object. The error object contains the following fields:
{
"error": {
"code": "ERROR_CODE",
"message": "A human-readable error message",
"details": {
// Additional error details (if available)
}
}
}
Common Error Codes
AUTHENTICATION_ERROR
: Invalid or missing API keyRATE_LIMIT_EXCEEDED
: You've exceeded your rate limitINVALID_REQUEST
: The request was malformed or missing required parametersRESOURCE_NOT_FOUND
: The requested resource could not be foundINTERNAL_SERVER_ERROR
: An unexpected error occurred on our servers
Handling Errors in Your Code
Here's an example of how to handle errors when making requests to the RUE API:
const axios = require('axios');
async function makeApiRequest() {
try {
const response = await axios.post('https://api.rue.ai/v1/scrape_metadata',
{ url: 'https://example.com' },
{
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'YOUR_API_KEY'
}
}
);
console.log('Success:', response.data);
} catch (error) {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.error('Error:', error.response.data.error);
console.error('Status:', error.response.status);
// Handle specific error codes
switch(error.response.data.error.code) {
case 'AUTHENTICATION_ERROR':
console.error('Invalid API key. Please check your credentials.');
break;
case 'RATE_LIMIT_EXCEEDED':
console.error('Rate limit exceeded. Please try again later.');
break;
// Add more cases for other error codes
default:
console.error('An unexpected error occurred.');
}
} else if (error.request) {
// The request was made but no response was received
console.error('No response received:', error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.error('Error:', error.message);
}
}
}
makeApiRequest();
Best Practices for Error Handling
- Always wrap API calls in try-catch blocks to handle potential errors
- Log errors for debugging purposes, but be careful not to log sensitive information
- Implement appropriate retry logic for transient errors (e.g., network issues)
- Provide meaningful error messages to your users without exposing sensitive details
- Monitor your error rates and investigate any sudden increases
If you encounter persistent errors or need further assistance, please don't hesitate to contact our support team.