Error Handling
How to handle API errors
When an error occurs, the API returns an appropriate HTTP status code and a JSON error response.
HTTP Status Codes
400 Bad Request- Invalid request parameters401 Unauthorized- Missing or invalid authentication403 Forbidden- Insufficient permissions404 Not Found- Resource not found405 Method Not Allowed- HTTP method not supported500 Internal Server Error- Server error
Error Response Format
Error responses include:
Message- Human-readable error descriptionErrorCode- Numeric error code for programmatic handlingDetails- Additional error details (may be null)
Common Errors
401 Unauthorized
Your access token is missing, expired, or invalid. Request a new token.
400 Bad Request
Check the error message for specific validation failures. Common causes:
- Missing required fields
- Invalid field values
- Incorrect data types
- Duplicate resource names
Best Practices
- Always check HTTP status codes
- Log error messages for debugging
- Implement retry logic for 5xx errors
- Handle 401 errors by refreshing the token
Code Examples
# Error Response Example
{
"Message": "Specified name is taken by an existing snippet",
"ErrorCode": 11001,
"Details": null
}
# Handling Errors (JavaScript)
try {
const response = await fetch(url, options);
if (!response.ok) {
const error = await response.json();
console.error('API Error:', error.Message);
throw new Error(error.Message);
}
return await response.json();
} catch (error) {
// Handle network or parsing errors
console.error('Request failed:', error);
}