Overview
The Satsuma API uses standard HTTP status codes and detailed error responses to help you diagnose and handle issues. This guide covers common error scenarios and best practices for robust error handling.HTTP Status Codes
Success Codes (2xx)
200 OK- Request succeeded201 Created- Resource created successfully202 Accepted- Request accepted for processing204 No Content- Request succeeded with no response body
Client Error Codes (4xx)
400 Bad Request- Invalid request syntax or parameters401 Unauthorized- Invalid or missing API key403 Forbidden- Insufficient permissions404 Not Found- Resource does not exist409 Conflict- Request conflicts with current state422 Unprocessable Entity- Validation errors429 Too Many Requests- Rate limit exceeded
Server Error Codes (5xx)
500 Internal Server Error- Unexpected server error502 Bad Gateway- Upstream service error503 Service Unavailable- Temporary service outage504 Gateway Timeout- Request timeout
Error Response Format
All errors return a consistent JSON structure:Common Error Codes
Authentication Errors
INVALID_API_KEY
INVALID_API_KEY
Status: 401
Cause: API key is malformed, expired, or doesn’t exist
Solution: Verify your API key and ensure it’s not truncated
Cause: API key is malformed, expired, or doesn’t exist
Solution: Verify your API key and ensure it’s not truncated
INSUFFICIENT_PERMISSIONS
INSUFFICIENT_PERMISSIONS
Status: 403
Cause: API key lacks required permissions for the endpoint
Solution: Use a key with appropriate permissions
Cause: API key lacks required permissions for the endpoint
Solution: Use a key with appropriate permissions
Validation Errors
VALIDATION_ERROR
VALIDATION_ERROR
Status: 422
Cause: Request data fails validation rules
Solution: Fix the invalid fields listed in the details array
Cause: Request data fails validation rules
Solution: Fix the invalid fields listed in the details array
MISSING_REQUIRED_FIELD
MISSING_REQUIRED_FIELD
Status: 400
Cause: Required request parameter is missing
Solution: Include all required fields in your request
Cause: Required request parameter is missing
Solution: Include all required fields in your request
Resource Errors
RESOURCE_NOT_FOUND
RESOURCE_NOT_FOUND
Status: 404
Cause: Requested resource doesn’t exist or has been deleted
Solution: Verify the resource ID and ensure it exists
Cause: Requested resource doesn’t exist or has been deleted
Solution: Verify the resource ID and ensure it exists
RESOURCE_CONFLICT
RESOURCE_CONFLICT
Status: 409
Cause: Request conflicts with current resource state
Solution: Check resource state and retry with correct data
Cause: Request conflicts with current resource state
Solution: Check resource state and retry with correct data
Business Logic Errors
INSUFFICIENT_INVENTORY
INSUFFICIENT_INVENTORY
Status: 422
Cause: Requested quantity exceeds available inventory
Solution: Reduce quantity or choose different product
Cause: Requested quantity exceeds available inventory
Solution: Reduce quantity or choose different product
PAYMENT_FAILED
PAYMENT_FAILED
Status: 422
Cause: Payment processing failed
Solution: Use valid payment method or contact payment provider
Cause: Payment processing failed
Solution: Use valid payment method or contact payment provider
Rate Limiting
RATE_LIMIT_EXCEEDED
RATE_LIMIT_EXCEEDED
Status: 429
Cause: Too many requests in time window
Solution: Implement backoff and retry after specified time
Cause: Too many requests in time window
Solution: Implement backoff and retry after specified time
Implementing Error Handling
Basic Error Handling
Retry Logic with Backoff
Implement exponential backoff for transient errors:Error-Specific Handling
Handle different error types appropriately:Circuit Breaker Pattern
Prevent cascade failures with a circuit breaker:Monitoring & Alerting
Error Tracking
Track errors for monitoring and debugging:Health Checks
Implement health checks to monitor API status:Best Practices
Error Handling Strategy
- Fail Fast: Return errors immediately for invalid requests
- Graceful Degradation: Provide fallback functionality when possible
- User-Friendly Messages: Show helpful error messages to end users
- Detailed Logging: Log full error context for debugging
Retry Guidelines
- Retry transient errors: Network issues, 5xx errors, rate limits
- Don’t retry permanent failures: 4xx errors (except 429)
- Use exponential backoff: With jitter to prevent thundering herd
- Respect rate limits: Use server-provided retry-after values
Security Considerations
- Never log sensitive data: API keys, payment info, personal data
- Validate all inputs: Even when retrying failed requests
- Monitor for anomalies: Unusual error patterns may indicate attacks
- Rotate compromised keys: Immediately if invalid key errors occur
Troubleshooting Common Issues
Getting 401 errors with valid API key
Getting 401 errors with valid API key
- Ensure API key is not truncated in environment variables
- Check that you’re using the correct header name (
Authentication) - Verify you’re hitting the correct environment (staging vs production)
- Try regenerating your API key if the issue persists
Intermittent timeout errors
Intermittent timeout errors
- Implement retry logic with exponential backoff
- Check your network connectivity and DNS resolution
- Consider increasing request timeout limits
- Monitor our status page for incidents
High error rates during peak traffic
High error rates during peak traffic
- Review your rate limiting and implement proper backoff
- Consider request batching to reduce API calls
- Implement caching for frequently accessed data
- Contact support for rate limit increases if needed
Getting Help
When reporting errors, include:- Request ID from the error response
- Full error message and code
- Request payload (without sensitive data)
- Timestamp and retry attempts
- Your API key prefix (first 8 characters)