Skip to main content

Error Handling

Learn how to handle errors gracefully in your vfrog.ai integration.

HTTP Status Codes

CodeMeaningAction
200SuccessProcess results
400Bad RequestFix request parameters
401UnauthorizedCheck API key
403ForbiddenCheck key status/permissions
408TimeoutRetry with exponential backoff
429Rate LimitedWait and retry
500Server ErrorRetry with backoff
502Bad GatewayRetry 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

  1. Implement exponential backoff
  2. Log all errors with context
  3. Set up error monitoring (Sentry, etc.)
  4. Handle network errors gracefully
  5. Provide user-friendly error messages