Error Handling Patterns
This page covers advanced error handling — classification, telemetry, structured logging, and circuit breakers. For the basics (try/catch, retry, re-auth, user-friendly messages), see the Error Handling guide.Error Classification
com.privacyboost.defaults ships SdkException.category and SdkException.isRetryable extensions that bucket every variant into one of seven categories. Use them to make UI/operational decisions without exhaustively matching every case.
| Category | Meaning | Recommended UI | Retry? |
|---|---|---|---|
Auth | Session/auth flow failed | Re-prompt sign-in | No (but re-auth and try once) |
Network | Connectivity / DNS / timeout | ”Check your connection” | Yes, with backoff |
Validation | Input is malformed | Inline form error | No |
Permission | User cancelled / forbidden | Silent dismiss or contact support | No |
RateLimit | Too many requests | Wait + auto-retry | Yes, after retryAfterMs |
Server | Backend / proof / merkle failure | Generic error toast | Sometimes (check isRetryable) |
Internal | Bug or invariant violation | ”Something went wrong” + report | No |
Structured Logging
Log SDK errors with stable fields so they’re queryable in your log pipeline (Logcat → Crashlytics, Datadog, etc.).Error Reporting Integration
Firebase Crashlytics
pb.category custom key lets you build dashboards that group errors by class — “auth-class errors are spiking” is more actionable than “twelve different variants are spiking.”
Sentry
Filter Out Noise
User cancellations (SignatureRejected) and validation errors aren’t bugs — don’t ship them to your error tracker:
Operation-Scoped Wrapping
Wrap each meaningful SDK call so logging, reporting, and retry sit in one place.Circuit Breaker
If the backend is degraded, hammering it with retries makes things worse. Wrap operations in a circuit breaker that trips after consecutive server-class failures.category makes that distinction trivial.
Telemetry: Operation Latency by Outcome
Pair errors with timings — slow successes are interesting too.OpMetric to Firebase Performance, Datadog RUM, or your own analytics pipeline.
Best Practices
- Branch on
category, not on individual variants — UI logic stays small and stable across SDK upgrades. - Filter user-class errors out of error reporters —
PermissionandValidationare noise. - Tag every report with
pb.categoryandpb.variant— makes dashboards actually useful. - Trip circuit breakers only on
ServerandNetwork— never on auth or validation. - Pair errors with timings — a slow success that turns into a timeout is worth catching upstream.
Next Steps
- Performance
- Error Handling guide — basics
- Error Handling Concepts — cross-platform error model