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
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.category makes that distinction trivial.
Telemetry: Operation Latency by Outcome
Pair errors with timings — slow successes are interesting too.OpMetric to MetricKit, Firebase Performance, 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 —
.permissionand.validationare noise. - Tag every report with
pb.categoryandpb.variant— makes dashboards actually useful. - Trip circuit breakers only on
.serverand.network— 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