Error Response Format
All errors follow a consistent format:Status Codes
Request successful
Resource created successfully (e.g., user registration)
Validation error or invalid request format
- Missing required fields
- Invalid data format
- Validation rule violations (e.g., password too short)
Authentication required or failed
- Missing Authorization header
- Invalid or expired token
- Invalid credentials
- Invalid 2FA code
Request blocked by security system
- Rate limit exceeded (Arcjet)
- Bot detected (Arcjet)
- Shield protection triggered
Resource not found
- User not found
- Session not found
- Invalid endpoint
Resource conflict
- User already exists
- Duplicate resource
Server error
- Database error
- Unexpected exception
- Configuration error
Common Error Scenarios
Validation Errors (400)
- Invalid email format
- Password too short
- Missing required fields
- Invalid data types
Authentication Errors (401)
- Wrong email/password
- Expired token
- Invalid 2FA code
- Missing Authorization header
Rate Limit Errors (403)
- Too many requests in short time
- Bot detection triggered
- Shield protection activated
Not Found Errors (404)
- Invalid user ID
- Resource deleted
- Invalid endpoint path
Error Handling Best Practices
Client-Side Handling
Client-Side Handling
Retry Logic
Retry Logic
Implement exponential backoff for:
- 500 errors (server errors)
- 403 errors (rate limits)
- Network failures
- 400 errors (validation - fix request)
- 401 errors (authentication - re-authenticate)
- 404 errors (not found - check resource)
Logging
Logging
Log all errors with:
- Error message
- Status code
- Request details (without sensitive data)
- Timestamp
- User ID (if authenticated)
Internal Error Logging
Errors are logged server-side with different levels:- Warn: Validation errors, failed auth attempts
- Error: Server errors, unexpected exceptions
- Info: Successful operations, important events