Overview
Grain SDK handles most errors automatically with retries and fallbacks. However, understanding error scenarios helps you build robust applications.Automatic Error Handling
The SDK automatically handles common failures: Network Errors: Retries with exponential backoff Rate Limits: Backs off and retries later Server Errors: Retries failed requests Invalid Data: Logs warning, continues You don’t need to handle these explicitly.Manual Error Handling
For critical operations, catch errors explicitly:Track Method Errors
Thetrack method is fire-and-forget by default:
flush: true, it returns a Promise you can catch:
Configuration Errors
Config methods degrade gracefully:React Hook Error Handling
Hooks provide error states:Authentication Errors
JWT token errors are thrown, so catch them:Network Offline
When offline, events queue locally:Debug Mode
Enable debug mode to see detailed error information:Error Types
Common errors you might encounter: Network Errors:Failed to fetch, Network request failed
- Usually temporary - SDK retries automatically
Unauthorized, Invalid token
- Check your auth configuration
Invalid event, Missing required field
- Review your event structure
Too many requests
- SDK backs off automatically
Handling Critical Failures
For must-not-fail scenarios:Fallback Strategies
Provide fallbacks for failed operations:Best Practices
1. Don’t Block UI: Never wait indefinitely for analyticsflush: true and manual retries for important events
5. Monitor Errors: Check dashboard for error patterns