Error Handling
Error Handling
When using the 3spread API, you may encounter errors. This guide will help you understand and handle these errors effectively.
Error Response Format
All API errors are returned in a consistent JSON format:
{
"error": {
"code": "ERROR_CODE",
"message": "A human-readable error message"
}
}
Common Error Codes
Here are some common error codes you might encounter:
400 Bad Request
: The request was invalid or cannot be served.401 Unauthorized
: The request requires authentication.403 Forbidden
: The server understood the request but refuses to authorize it.404 Not Found
: The requested resource could not be found.429 Too Many Requests
: You have exceeded the rate limit.500 Internal Server Error
: The server encountered an unexpected condition.
Handling Errors
When working with the 3spread API, it's important to implement proper error handling in your code. Here's an example of how you might handle errors in JavaScript:
async function fetchData(endpoint) {
try {
const response = await fetch(`https://api.3spread.com/v1${endpoint}`, {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(`API Error: ${errorData.error.message}`);
}
return await response.json();
} catch (error) {
console.error('Error fetching data:', error);
// Handle the error appropriately in your application
}
}
By implementing robust error handling, you can ensure that your application gracefully handles any issues that may arise when interacting with the 3spread API.
On This Page