Skip to main content

HTTP Return Codes

Success Codes

HTTP CodeDescription
200OK - Request completed successfully
201Created - Resource created successfully
204No Content - Request successful, no content returned

Client Error Codes

HTTP CodeDescription
400Bad Request - Malformed request syntax or invalid parameters
401Unauthorized - Missing or invalid authentication token
403Forbidden - Valid token but insufficient permissions
404Not Found - Resource does not exist
409Conflict - Request conflicts with current state
422Unprocessable Entity - Validation error
429Too Many Requests - Rate limit exceeded

Server Error Codes

HTTP CodeDescription
500Internal Server Error - Unexpected server error
502Bad Gateway - Upstream service unavailable
503Service Unavailable - Server temporarily unavailable
504Gateway Timeout - Upstream service timeout

Handling Errors

Always check the HTTP status code first, then parse the response body for detailed error information:

response = requests.post(url, json=data, headers=headers)

if response.status_code == 200:
result = response.json()["data"]
elif response.status_code == 401:
# Token expired, refresh and retry
refresh_token()
retry_request()
elif response.status_code == 429:
# Rate limited, wait and retry
time.sleep(int(response.headers.get("Retry-After", 60)))
retry_request()
else:
error = response.json()
print(f"Error {error['errno']}: {error['error']}")