Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Error handling & reconnection

DNotifier SDKs surface connection failures, send errors, and disconnect events through thrown exceptions and onDisconnected callbacks. The SDK does not auto-reconnect — your app owns retry policy and offline UX.


Common error sources

Phase
Error
Typical cause

connect()

Thrown exception

Wrong secret, invalid appId, plan issue, network

send() / sendBinary()

Not connected

Called before connect() or after disconnect

send()

Validation error

Missing senderId, receiverId, or receiverIds

Transport

onDisconnected

Network loss, server close, explicit disconnect()


Handle disconnects

Register onDisconnected at construction:

const notifier = new DNotifier({
  // ...
  onDisconnected: ({ code, reason }) => {
    console.log("Disconnected:", code, reason);
    showOfflineBanner();
    scheduleReconnect();
  },
});

Dart:


Reconnection pattern

Dart equivalent:


Send error handling


Auth failures at connect

Never log secret or authToken in production error reports.


Chunk reassembly failures

If the connection drops while a large message is chunking:

  • Partial chunks are discarded on the receiver

  • The sender should retry the full send() after reconnect

  • Consider showing "Message failed to send" in chat UI with a retry button

→ Large messages & chunking


Explicit disconnect

Use when the user logs out or your app tears down the realtime session.


Production checklist

  1. Listen to onDisconnected — update UI and pause sends

  2. Exponential backoff — avoid hammering auth on flaky networks

  3. Idempotent history load — after reconnect, fetchChatHistory to fill gaps

  4. Deduplicate by metadata.id — if your app retries sends

→ Production checklist


Last updated