Documentation Index
Fetch the complete documentation index at: https://zapo.to/llms.txt
Use this file to discover all available pages before exploring further.
zapo surfaces problems through three event channels:
connectionwithstatus: 'close'— the socket dropped, carrying areasonand optionalcode.stream_failure— a stream-level failure, often just before a close.stanza_error— a single request/stanza was rejected, without dropping the connection.
isLogout, graceful shutdown), see Reconnection. This page is about understanding why something failed.
Disconnect reasons
Theclose event is { status: 'close', reason, code, isLogout }. reason is a WaDisconnectReason string; code is a numeric WaConnectionCode (or null). Use them to decide whether to reconnect:
stream_error_force_login (code 515) is not fatal — it’s a routine “reconnect now” the server sends right after pairing and occasionally during a session. Just reconnect with the stored credentials.stream_error_force_login, stream_error_ack, stream_error_xml_not_well_formed, stream_error_other, failure_service_unavailable, and comms_stopped. client_disconnected means you called disconnect() — expected, don’t reconnect.
Code reference
When present,code (on the close event and on stream_failure.failureCode) is one of:
| Code | Meaning | Action |
|---|---|---|
401 | Not authorized | Re-pair |
402 | Temporarily banned | Back off hard |
403 | Locked | Stop |
405 | Client too old | Bump version |
406 | Banned | Stop |
409 | Bad user agent | Fix device fingerprint |
500 | Internal server error | Retry later |
503 | Service unavailable | Back off and retry |
515 | Reconnect required | Reconnect now |
516 | Forced logout | Re-pair (isLogout: true) |
WA_DISCONNECT_REASONS and the 515/516 stream codes in WA_STREAM_SIGNALING, both exported from the package root. The numeric code values are typed as WaConnectionCode (also exported).
Stream failures
stream_failure (WaIncomingFailureEvent) carries the raw failure detail and usually precedes a disconnect — log it for context:
Error stanzas
stanza_error (WaIncomingErrorStanzaEvent) reports that a single stanza was rejected — for example a malformed query or a throttled request. The connection stays up:
client.message.send or client.lowlevel.query typically rejects its own promise too, so wrap individual calls in try/catch for per-operation handling; use stanza_error for visibility into errors that aren’t tied to a call you await.
See also
Reconnection
The backoff loop and
isLogout handling.Troubleshooting
Common pitfalls and quick answers.
