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
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 reconnectConsider showing "Message failed to send" in chat UI with a retry button
Explicit disconnect
Use when the user logs out or your app tears down the realtime session.
Production checklist
Listen to
onDisconnected— update UI and pause sendsExponential backoff — avoid hammering auth on flaky networks
Idempotent history load — after reconnect,
fetchChatHistoryto fill gapsDeduplicate by
metadata.id— if your app retries sends
Related topics
Chat history — recover missed messages after reconnect
Last updated