IrtError: reason property
Available since
@irtio/client 5.0BrowsersNodeThe reason read-only property of the IrtError interface is the reason the router or the room gave for the error, or "" when there’s none.
Value
A string. It’s one of:
- the close reason the router or the room gave, such as the reason room code passed to
room.kick()orroom.ban() - for a call the room failed, the message of the error its handler threw, such as a
CallRejected’s, or why the call’s args were refused - for an aborted connect or call, the
signal’s reason as a string ""when there’s none
Description
reason is written for players, so a game can show it: a kick’s reason, or a game rule a call handler refused a move for. message also contains it, after a description of the error that’s written for developers.
Examples
Showing why a move was refused
The room refuses a move out of turn with CallRejected. The client shows the room’s reason to the player.
// move.ts
import { call, connect, defineCalls, defineSchema, IrtError } from "@irtio/client";
const schema = defineSchema({ calls: defineCalls({ move: call({ cell: "u8" }) }) });
const room = await connect("tic-tac-toe", { schema });
const status = document.querySelector("#status")!;
export async function move(cell: number) {
try {
await room.calls.move({ cell });
} catch (e) {
if (e instanceof IrtError && e.name === "OperationError") status.textContent = e.reason;
else throw e;
}
}
See also
IrtError.messageCallRejected, for refusing a call in the room- Calls, for each call error’s reason
Runtime availability
| Browsers | Node | |
|---|---|---|
reason | 5.0 | 5.0 |