Error Handling
Learn how to handle errors gracefully in your vfrog.ai integration.
HTTP Status Codes
| Code | Meaning | Action |
|---|---|---|
| 200 | Success | Process results |
| 400 | Bad Request | Fix request parameters |
| 401 | Unauthorized | Check API key |
| 403 | Forbidden | Check key status/permissions |
| 408 | Timeout | Retry with exponential backoff |
| 429 | Rate Limited | Wait and retry |
| 500 | Server Error | Retry with backoff |
| 502 | Bad Gateway | Retry with backoff |
Error Response Format
{
"error": "Error Type",
"message": "Human-readable description",
"error_code": "MACHINE_READABLE_CODE",
"details": {...}
}
Common Errors
Authentication Errors
try:
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
except requests.exceptions.HTTPError as e:
if e.response.status_code == 401:
print("Invalid API key")
elif e.response.status_code == 403:
print("API key suspended or no permissions")
Rate Limiting
import time
def make_request_with_retry(url, headers, data):
max_retries = 3
for attempt in range(max_retries):
response = requests.post(url, headers=headers, json=data)
if response.status_code == 429:
retry_after = int(response.headers.get('Retry-After', 60))
time.sleep(retry_after)
continue
return response
raise Exception("Max retries exceeded")
Timeout Handling
try:
response = requests.post(
sync_url,
headers=headers,
json=data,
timeout=30
)
except requests.exceptions.Timeout:
# Retry with exponential backoff
time.sleep(2 ** attempt)
continue
Best Practices
- Implement exponential backoff
- Log all errors with context
- Set up error monitoring (Sentry, etc.)
- Handle network errors gracefully
- Provide user-friendly error messages