HTTP Return Codes
Success Codes
| HTTP Code | Description |
|---|---|
| 200 | OK - Request completed successfully |
| 201 | Created - Resource created successfully |
| 204 | No Content - Request successful, no content returned |
Client Error Codes
| HTTP Code | Description |
|---|---|
| 400 | Bad Request - Malformed request syntax or invalid parameters |
| 401 | Unauthorized - Missing or invalid authentication token |
| 403 | Forbidden - Valid token but insufficient permissions |
| 404 | Not Found - Resource does not exist |
| 409 | Conflict - Request conflicts with current state |
| 422 | Unprocessable Entity - Validation error |
| 429 | Too Many Requests - Rate limit exceeded |
Server Error Codes
| HTTP Code | Description |
|---|---|
| 500 | Internal Server Error - Unexpected server error |
| 502 | Bad Gateway - Upstream service unavailable |
| 503 | Service Unavailable - Server temporarily unavailable |
| 504 | Gateway 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']}")