MiteSDK

Error Tracking

Which JS errors Mite captures for you, which ones need a call, and how to tune what is sent.

Mite sends JavaScript errors to your dashboard. Uncaught errors, unhandled promise rejections, and render errors inside MiteErrorBoundary are captured for you. Errors your own code catches need one call: mite.errors.capture(error).

Each occurrence joins a group for the same error. Triage labels the group as a duplicate, recurring, a real issue, a non-issue, or noise. Real issues become bug reports in your dashboard. Errors do not count against your report quota.

What is automatic and what is not

ErrorCapturedHow
Uncaught JS errorAutomaticallyThe SDK wraps the React Native global error handler. The previous handler still runs
Unhandled promise rejectionAutomatically, on HermesTracked from the moment you construct Mite, even if init() is never called
Render error inside <MiteErrorBoundary>AutomaticallySent with the component stack
Error your code catchesOnly when you call mite.errors.capture(error) or captureError(error)Sent as handled
Native iOS or Android crashNoNot supported yet

Automatic capture needs an apiKey. Without one, nothing is sent.

Capturing a caught error

Call mite.errors.capture() inside a catch block. It never throws and never waits, so it cannot break your error path.

try {
  await checkout()
} catch (error) {
  mite.errors.capture(error)
  showToast('Checkout failed')
}

Where no instance is at hand, such as a utility module, use the top-level captureError. It does the same thing.

import { captureError } from '@usemite/sdk'

captureError(error, { context: { screen: 'checkout' } })

Both take optional CaptureOptions:

interface CaptureOptions {
  /** The error took the app down. Sent at once. */
  fatal?: boolean
  /** The app caught the error itself. Defaults to true for explicit calls. */
  handled?: boolean
  /** Extra flat context, merged over the SDK's own environment keys. */
  context?: Record<string, string>
}

The latest captured error is also attached to the next feedback as last_error_message and last_error_stack.

Render errors

Wrap a tree in MiteErrorBoundary to send its render errors and show a fallback in place of a blank screen.

import { MiteErrorBoundary } from '@usemite/sdk'

<MiteErrorBoundary fallback={({ reset }) => <Retry onPress={reset} />}>
  <App />
</MiteErrorBoundary>

See MiteErrorBoundary for its props.

How errors are sent

  • Batched. The SDK sends buffered errors 5 seconds after the first one, or as soon as 20 are waiting.
  • Fatal errors go at once. An error that takes the app down is sent immediately.
  • Kept across launches. Buffered errors are saved in identityStorage. If the app dies before they go out, the next launch sends them after init(). A synchronous store such as MMKV makes this most reliable.
  • Flushed on background. After init(), the SDK sends the buffer when the app moves to the background.
  • Throttled. Identical errors within 2 seconds count once, so a render loop stays one event. A session sends at most 30 errors per minute. At most 50 errors wait in the buffer.

To send the buffer now, for example before a planned restart:

await mite.errors.flush()

Tuning

OptionTypeDefaultDescription
captureUncaughtErrorsbooleantrueCapture uncaught JS errors
captureUnhandledRejectionsbooleantrueCapture unhandled promise rejections. Hermes only
enableErrorTrackingbooleantrueSend errors to Mite. When false, the SDK still keeps the latest error for feedback
ignoreErrorsArray<string | RegExp>—Drop errors whose message contains a string or matches a pattern
beforeSendError(event: MiteErrorEvent) => MiteErrorEvent | null—Edit or scrub an event before it is sent. Return null to drop it
const mite = new Mite({
  apiKey: process.env.EXPO_PUBLIC_MITE_API_KEY,
  identityStorage: new MMKV(),
  ignoreErrors: ['Network request failed', /^AbortError/],
  beforeSendError: event =>
    event.message.includes('token=') ? { ...event, message: '[redacted]' } : event,
})

Moving from 1.0

recordError and the instance methods mite.recordError, mite.captureError, and mite.flushErrors still work. They are deprecated and are removed in 2.0.

1.0Now
mite.recordError(e) or mite.captureError(e)mite.errors.capture(e)
recordError(e) (top-level)captureError(e)
mite.flushErrors()mite.errors.flush()

On this page