Error Handling
Proper error handling ensures your application remains stable even if usage tracking fails.
The Golden Rule
Never let usage tracking failures break your main application!
If tracking fails, log the error and continue. Your users care about your app working, not whether usage was tracked.
Node.js/TypeScript
typescript
1try {
2 await paygentClient.sendUsage(agent, customer, indicator, usageData);
3} catch (error) {
4 // Log but don't throw - app continues normally
5 console.error('Failed to track usage:', error);
6}Python
python
1try:
2 client.send_usage(agent, customer, indicator, usage_data)
3except Exception as e:
4 # Log but don't raise - app continues
5 logging.warning(f"Failed to track usage: {e}")Go
go
1err := client.SendUsage(agent, customer, indicator, usageData)
2if err != nil {
3 // Log but don't return error - app continues
4 log.Printf("warning: failed to track usage: %v", err)
5}Production Best Practices
- • Use try-catch/error handling around all tracking calls
- • Log errors for debugging but don't crash the app
- • Consider adding retry logic for transient failures
- • Monitor error rates in your logging system
Was this page helpful?
Need help? Contact us at support@withpaygent.com