CallRejected
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe CallRejected class of the Room API is an error a call handler or onRequest throws to refuse a request as an expected outcome, such as a game rule. It extends Error.
Constructor
new CallRejected(message)
message- Why the request was refused, sent to the caller.
Instance properties
CallRejected.name"CallRejected".
Description
A call or server API message refused with CallRejected fails as for any error thrown: the client’s call rejects with its message, and a server API message gets a 422 room_error reply with it. The difference is that the room doesn’t log it, while any other error is logged at error level with its stack.
Examples
Refusing a move out of turn
// turns.ts
import { call, CallRejected, defineCalls, defineRoom, defineSchema, entity } from "@irtio/room";
const Board = entity("board", { turn: "string" });
const schema = defineSchema({ state: Board, calls: defineCalls({ move: call({ cell: "u8" }) }) });
export default defineRoom({
schema,
calls: {
move({ cell }, { room, connection }) {
if (room.state.turn !== connection.player) throw new CallRejected("it isn't your turn");
if (cell > 8) throw new CallRejected("no such cell");
},
},
});
See also
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
CallRejected | 0.1 | 0.1 | 0.1 | 0.1 |