Error Handling
Comprehensive error handling strategies for the ThriveTech API, including error codes, recovery strategies, and best practices.
Error Response Format
All errors follow a consistent JSON structure:
json
{"error": "error_code","message": "Human-readable error message","details": { "field": "Additional context" },"correlationId": "uuid-for-support-tracking"}
HTTP Status Codes
| Status | Category | Description |
|---|---|---|
| 400 | Client Error | Invalid request parameters |
| 401 | Authentication | Invalid or missing credentials |
| 402 | Payment Required | Payment verification failed |
| 403 | Forbidden | Insufficient permissions |
| 404 | Not Found | Resource doesn't exist |
| 409 | Conflict | Resource state conflict |
| 422 | Validation | Request validation failed |
| 429 | Rate Limited | Too many requests |
| 500 | Server Error | Internal server error |
| 503 | Unavailable | Service temporarily unavailable |
Error Codes Reference
Authentication Errors (401)
| Error Code | Description | Recovery |
|---|---|---|
invalid_api_key | API key is invalid or revoked | Verify key in dashboard |
missing_api_key | API key header not provided | Add authentication header |
expired_api_key | API key has expired | Generate new key |
invalid_token | JWT token is invalid | Re-authenticate |
expired_token | JWT token has expired | Refresh token |
License Errors
| Error Code | Status | Description | Recovery |
|---|---|---|---|
invalid_license | 404 | License key not found | Verify license key |
license_expired | 403 | License has expired | Prompt for renewal |
license_suspended | 403 | License is suspended | Contact support |
license_revoked | 403 | License has been revoked | Check refund status |
trial_already_used | 409 | Trial already activated | Prompt for purchase |
device_limit_reached | 409 | Max devices exceeded | Deactivate a device |
device_mismatch | 403 | License not valid for device | Activate on this device |
Payment Errors (402)
| Error Code | Description | Recovery |
|---|---|---|
payment_not_found | Payment not found in store | Verify transaction ID |
payment_failed | Payment was declined | Retry payment |
payment_pending | Payment is processing | Wait for webhook |
receipt_invalid | Invalid receipt data | Get fresh receipt |
store_unavailable | Payment store unreachable | Retry later |
Validation Errors (400/422)
| Error Code | Description | Recovery |
|---|---|---|
invalid_request | Malformed request body | Check request format |
missing_field | Required field missing | Add required field |
invalid_field | Field value invalid | Fix field value |
invalid_device_fingerprint | Invalid fingerprint format | Regenerate fingerprint |
Rate Limit Errors (429)
| Error Code | Description | Recovery |
|---|---|---|
rate_limit_exceeded | Too many requests | Wait for reset time |
quota_exceeded | Daily quota exceeded | Upgrade plan or wait |
Retry Strategy
Use exponential backoff with jitter for transient errors:
javascript
async function requestWithRetry(fn, maxRetries = 3, baseDelay = 1000) {let lastError;for (let attempt = 0; attempt < maxRetries; attempt++) {try {return await fn();} catch (error) {lastError = error;// Don't retry client errors (4xx) except rate limitsif (error.statusCode >= 400 && error.statusCode < 500&& error.statusCode !== 429) {throw error;}if (attempt === maxRetries - 1) throw error;const delay = Math.min(baseDelay * Math.pow(2, attempt) + Math.random() * 1000,30000);await new Promise(resolve => setTimeout(resolve, delay));}}throw lastError;}
Offline Mode
When validation fails due to network issues, allow a grace period before blocking functionality:
- Cache validation results — Store the last successful validation response locally
- Check grace period — Allow offline use for a configurable period (recommended: 7 days)
- Prompt reconnection — After the grace period, prompt the user to connect to the internet
javascript
// Simplified offline validationfunction validateOffline(cachedLicense) {const daysSinceValidation =(Date.now() - new Date(cachedLicense.lastValidated)) / (1000 * 60 * 60 * 24);if (daysSinceValidation > 7) {return { valid: false, reason: 'Please connect to the internet to validate your license.' };}if (new Date(cachedLicense.validUntil) < new Date()) {return { valid: false, reason: 'Your license has expired.' };}return { valid: true, offline: true, gracePeriodRemaining: Math.ceil(7 - daysSinceValidation) };}
Multi-Language Error Messages
Error messages support localization via the Accept-Language header. Supported: en-US, es-ES.
Contacting Support
When contacting support, include:
- Correlation ID — from the error response
- Error Code — the specific error code
- Timestamp — when the error occurred
- Client Version — your application version
Was this helpful?
