API Error Codes
Reference guide for Toggly API error codes and how to resolve them.
HTTP Status Codes
401 Unauthorized
Meaning: Authentication failed or token is invalid.
Common Causes:
- Invalid or missing Bearer token
- Expired token
- Token was invalidated (logged out)
- Using API key instead of Bearer token
Solutions:
# Verify your token works
curl -H "Authorization: Bearer YOUR_TOKEN" \
https://app.toggly.io/api/v2/applications
# If it fails, sign in again to get a new token
When this happens:
- API requests (not SDK usage)
- Browser extension requests
- CLI operations
SDK Impact: SDKs use app keys, not bearer tokens, so this typically doesn't affect SDK operations.
403 Forbidden
Meaning: You don't have permission to access this resource.
Common Causes:
- Insufficient permissions for the requested action
- Not a member of the team/workspace
- Resource belongs to different organization
- Plan limitation (feature not included in your tier)
Solutions:
-
Check Team Membership:
- Go to Settings → Teams
- Verify you're a member
- Check your role (Viewer, Member, Admin)
-
Verify Resource Ownership:
- Confirm you're in the correct workspace
- Check if the resource exists
- Verify you have permissions
-
Plan Limitations:
- Some features require paid plans
- Check if feature is included in your subscription
- Upgrade your plan if needed
404 Not Found
Meaning: The requested resource doesn't exist.
Common Causes:
- Feature flag doesn't exist
- Wrong environment
- Typo in feature key
- Resource was deleted
Solutions:
// Verify the feature key is correct
const featureKey = 'my-feature'; // Check spelling
// Verify it exists in the dashboard
console.log('Looking for feature:', featureKey);
// Check if it exists in this environment
const exists = await toggly.featureExists(featureKey);
429 Too Many Requests
Meaning: You've exceeded the rate limit.
Common Causes:
- Making too many API requests
- Not caching definitions locally
- Calling API in a tight loop
- DDoS or abuse detection triggered
Solutions:
- Implement Caching:
// Cache definitions locally
const toggly = new TogglyClient({
appKey: 'your-key',
environment: 'production',
cacheTimeout: 300000, // Cache for 5 minutes
});
- Batch Operations:
// ❌ Bad - multiple individual calls
const flag1 = await toggly.isEnabled('feature-1');
const flag2 = await toggly.isEnabled('feature-2');
const flag3 = await toggly.isEnabled('feature-3');
// ✅ Good - evaluate multiple flags at once
const results = await toggly.evaluateAll(['feature-1', 'feature-2', 'feature-3']);
- Check Rate Limits:
- See Rate Limits Documentation
- Contact support for increased limits
Rate Limits by Plan:
- Free: 100 requests/minute
- Paid: 1,000 requests/minute
- Enterprise: Custom limits
500 Internal Server Error
Meaning: Server encountered an error processing your request.
Common Causes:
- Temporary server issue
- Malformed request payload
- Server bug
Solutions:
- Retry with exponential backoff:
async function retryRequest(fn: () => Promise<any>, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (error.status === 500 && i < maxRetries - 1) {
await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, i)));
continue;
}
throw error;
}
}
}
-
Check Status Page:
- Visit status.toggly.io
- Check for ongoing incidents
-
Contact Support:
- If error persists, email [email protected]
- Include request ID from error response
- Provide timestamp and steps to reproduce
503 Service Unavailable
Meaning: Service is temporarily unavailable.
Common Causes:
- Scheduled maintenance
- Service deployment
- High load (rare)
Solutions:
- Check Status Page - status.toggly.io
- Wait and Retry - Usually resolves in 1-5 minutes
- Use Cached Values - SDKs should fall back to cached definitions
- Implement Fallback:
try {
await toggly.init();
} catch (error) {
if (error.status === 503) {
// Use default values or cached data
console.warn('Toggly unavailable, using defaults');
}
}
SDK-Specific Error Handling
Different SDKs handle errors differently:
- JavaScript - Promise rejections
- .NET - Try-catch with specific exceptions
- PHP - Exception handling
- Go - Error return values
General Error Handling Best Practices
1. Always Handle Errors
try {
await toggly.init();
} catch (error) {
console.error('Toggly initialization failed:', error);
// Use default flag values
}
2. Log Error Details
catch (error) {
console.error('Error details:', {
status: error.status,
message: error.message,
requestId: error.requestId, // If available
timestamp: new Date().toISOString()
});
}
3. Implement Fallbacks
const toggly = new TogglyClient({
appKey: 'your-key',
environment: 'production',
defaults: {
'new-feature': false, // Fallback if API fails
'beta-feature': false,
}
});
Getting Help
If authentication issues persist:
- Verify credentials in dashboard
- Check Common Issues guide
- Enable debug logging in your SDK
- Ask on GitHub Discussions
- Contact support at [email protected]