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

SdkError is a tagged union — every variant has a stable tag you can read at runtime. Unlike the iOS / Android SDKs (which ship a category extension in their Defaults libraries), the React Native binding leaves classification to you. This three-line helper mirrors the categories used on the other platforms:

Structured Logging

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

Error Reporting Integration

Sentry

The pb.category tag lets you build dashboards that group 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 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 categoryOf makes that distinction trivial.

Telemetry: Operation Latency by Outcome

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

Best Practices

  1. Branch on categoryOf(err), 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