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

PrivacyBoostDefaults ships an SdkError.category extension that buckets every variant into one of seven categories. Use it to make UI/operational decisions without exhaustively matching every case.

Structured Logging

Log SDK errors with stable fields so they’re queryable in Splunk / Datadog / OS Console.
privacy: .public on the variant/category fields keeps them queryable in Console.app; the message field is intentionally not marked public if it could include PII — review your own usage.

Error Reporting Integration

Sentry

The pb.category tag lets you build a dashboard that groups errors by class — “auth-class errors are spiking” is more actionable than “twelve different variants are spiking.”

Filter Out Noise

User cancellations (.signatureRejected) and validation errors (.invalidAmount, .invalidAddress) aren’t bugs — don’t ship them to your error tracker. Use a beforeSend-style filter:

Operation-Scoped Wrapping

Wrap each meaningful SDK call in a function that handles logging, reporting, and retry — application code stays clean.

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 MetricKit, Firebase Performance, 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 reporters.permission 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