Understanding API errors, status codes, and how to handle them in your application. All errors follow a consistent format for easy parsing and handling.
All error responses follow a consistent JSON structure with an error object:
{
"error": {
"message": "Human-readable error message",
"code": "ERROR_CODE",
"statusCode": 400
}
}messageHuman-readable description of the error
codeMachine-readable error identifier (optional)
statusCodeHTTP status code of the error
VALIDATION_ERRORThe request body contains invalid data or missing required fields.
Common Causes:
UNAUTHORIZEDAuthentication failed or API key is missing/invalid.
Common Causes:
FORBIDDENYou don't have permission to access this resource.
Common Causes:
NOT_FOUNDThe requested resource doesn't exist.
Common Causes:
RATE_LIMIT_EXCEEDED / USAGE_LIMIT_EXCEEDEDRate limit or usage quota exceeded.
Common Causes:
An unexpected error occurred on our servers.
Common Causes:
{
"error": {
"message": "Unauthorized",
"code": "UNAUTHORIZED",
"statusCode": 401
}
}{
"error": {
"message": "Validation failed: Invalid URL format",
"code": "VALIDATION_ERROR",
"statusCode": 400
}
}{
"error": {
"message": "Monthly usage limit reached. Upgrade your plan to continue.",
"code": "USAGE_LIMIT_EXCEEDED",
"statusCode": 429
}
}{
"error": {
"message": "Screenshot not found",
"code": "NOT_FOUND",
"statusCode": 404
}
}async function captureScreenshot(url) {
try {
const response = await fetch('https://www.snapshotai.dev/api/v1/screenshots', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ url })
});
if (!response.ok) {
const error = await response.json();
// Handle specific error codes
switch (error.error.code) {
case 'UNAUTHORIZED':
console.error('Invalid API key');
break;
case 'USAGE_LIMIT_EXCEEDED':
console.error('Monthly quota exceeded');
break;
case 'VALIDATION_ERROR':
console.error('Invalid URL:', error.error.message);
break;
default:
console.error('API error:', error.error.message);
}
throw new Error(error.error.message);
}
return await response.json();
} catch (error) {
console.error('Failed to capture screenshot:', error);
throw error;
}
}import requests
from requests.exceptions import HTTPError
def capture_screenshot(url):
try:
response = requests.post(
'https://www.snapshotai.dev/api/v1/screenshots',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
json={'url': url}
)
response.raise_for_status()
return response.json()
except HTTPError as e:
error_data = e.response.json()
error_code = error_data.get('error', {}).get('code')
error_message = error_data.get('error', {}).get('message')
# Handle specific error codes
if error_code == 'UNAUTHORIZED':
print('Invalid API key')
elif error_code == 'USAGE_LIMIT_EXCEEDED':
print('Monthly quota exceeded')
elif error_code == 'VALIDATION_ERROR':
print(f'Validation error: {error_message}')
else:
print(f'API error: {error_message}')
raise
except Exception as e:
print(f'Failed to capture screenshot: {str(e)}')
raiseBest Practices
Retry Strategy
Need Help?
If you're experiencing persistent errors or need help debugging, contact our support team with: