Aller au contenu

Error Handling

Ce contenu n’est pas encore disponible dans votre langue.

The Acme API uses standard HTTP status codes and returns detailed error information in JSON format.

All errors follow this structure:

{
"error": {
"code": "invalid_request",
"message": "The request body is missing required fields",
"details": {
"missing_fields": ["email", "name"]
}
}
}
CodeDescription
400Bad Request - Invalid parameters
401Unauthorized - Invalid or missing API key
403Forbidden - Insufficient permissions
404Not Found - Resource doesn’t exist
409Conflict - Resource already exists
422Unprocessable - Validation failed
429Too Many Requests - Rate limit exceeded
500Internal Error - Server-side issue
CodeDescription
invalid_requestThe request format is invalid
unauthorizedAuthentication failed
forbiddenAccess denied
not_foundResource not found
conflictResource conflict
validation_errorInput validation failed
rate_limitRate limit exceeded
internal_errorServer error
Terminal window
response=$(curl -s -w "\n%{http_code}" -X GET \
"https://api.acme.com/v2/users/invalid" \
-H "Authorization: Bearer YOUR_API_KEY")
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" != "200" ]; then
echo "Error: $body"
fi

For transient errors (5xx, 429), implement exponential backoff:

  1. Wait 1 second, retry
  2. Wait 2 seconds, retry
  3. Wait 4 seconds, retry
  4. Fail after 3 attempts

Check the Retry-After header for rate limit errors.