Skip to main content

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.

Structured Logging

Log SDK errors with stable fields so they’re queryable in your log pipeline (Logcat → Crashlytics, Datadog, etc.).
If your message field could include PII, scrub or omit it from logs.

Error Reporting Integration

Firebase Crashlytics

The 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.
Auth/validation/permission failures should not trip the breaker — they’re user-class problems, not service degradation. The classification by category makes that distinction trivial.

Telemetry: Operation Latency by Outcome

Pair errors with timings — slow successes are interesting too.
Forward OpMetric to Firebase Performance, Datadog RUM, or your own analytics pipeline.

Best Practices

  1. Branch on category, not on individual variants — UI logic stays small and stable across SDK upgrades.
  2. Filter user-class errors out of error reportersPermission and Validation are noise.
  3. Tag every report with pb.category and pb.variant — makes dashboards actually useful.
  4. Trip circuit breakers only on Server and Network — never on auth or validation.
  5. Pair errors with timings — a slow success that turns into a timeout is worth catching upstream.

Next Steps