# CallRejected

> The CallRejected class of the Room API is an error a call handler or onRequest throws to refuse a request as an expected outcome, without logging it.

The **`CallRejected`** class of the [Room API](/docs/room) 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

```ts
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

```ts
// 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

- [Calls](/docs/room/guides/calls), the guide
- [`call()`](/docs/room/call)
