Skip to content

Error codes ​

couchpad reports failures as Error objects whose message is a short code. Promises reject with them, and after joining, server errors arrive as error events with the code as the argument.

ts
try {
  await client.join(code, name);
} catch (e) {
  switch ((e as Error).message) {
    case 'room.notFound': return showMessage('Check the code on the TV.');
    case 'room.full': return showMessage('This room is full.');
    default: return showMessage('Could not join. Try again.');
  }
}

Client (phone) ​

Rejections of CouchClient.join().

CodeWhenWhat to do
join.timeoutNo room.joined within joinTimeoutMs (8 s)Check wsUrl, and that the server answers room.join
join.supersededjoin() was called again before this one finishedNothing; the newer call wins
join.closedclose() was called while joiningNothing; you closed it
room.*The server refused the join (see below)Depends on the code. Any code except room.full also clears the stored rejoin token

Host (TV) ​

Rejections of CouchHost.create() and CouchHost.resume().

CodeWhenWhat to do
room.badTokenresume() found no stored TV token, or the server rejected itCall create() instead
room.notFoundresume() asked for a room the server no longer hasCall create() instead
host.supersededcreate() or resume() was called again before this one settledNothing; the newer call wins
host.closedclose() was called while create() or resume() was pendingNothing; you closed it

When a resume is refused, the host forgets the stored token and stops its socket, so falling back is safe:

ts
const { code } = await host.resume().catch(() => host.create());

Server errors ​

The signaling server sends {t:'error', code, message?}. These are the codes couchpad knows about; servers may add their own, which are passed through unchanged.

CodeMeaning
room.notFoundNo room with that code
room.fullThe room has no free seat (the example server allows 8)
room.badRequestThe message was malformed
room.notInRoomA signal or relay came from a connection that has not joined a room
room.targetGoneThe host addressed a player whose socket is closed
room.badTokenThe tvToken did not match
room.rateLimitedThe connection sent too many messages

After a successful join or create, these arrive as events rather than rejections:

ts
client.on('error', (code: string) => console.warn('server error', code));
host.on('error', (code: string) => console.warn('server error', code));

Send results ​

send() and sendTo() return false instead of throwing:

MethodReturns false when
client.send(msg)The reliable queue is full (64), or msg would need more than 64 relay chunks
host.sendTo(id, msg)The player is unknown or has left, the queue is full, or msg would need more than 64 relay chunks

MIT licensed. Extracted from the Fire TV party game Cadabra.