Skip to navigation

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.


Python

try:
client.send_usage(agent, customer, indicator, usage_data)
except Exception as e:
# Log but don't raise - app continues
logging.warning(f"Failed to track usage: {e}")

Node.js / TypeScript

try {
await paygentClient.sendUsage(agent, customer, indicator, usageData);
} catch (error) {
// Log but don't throw - app continues normally
console.error('Failed to track usage:', error);
}

Go

err := client.SendUsage(agent, customer, indicator, usageData)
if err != nil {
// Log but don't return error - app continues
log.Printf("warning: failed to track usage: %v", err)
}

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