# HandoffFailed

> The HandoffFailed class of the Room API is the error room.handoff() rejects with when the router refused the handoff.

The **`HandoffFailed`** class of the [Room API](/docs/room) is the error `room.handoff()` rejects with when the handoff couldn't be made. Nobody moves. It extends `Error`.

## Instance properties

`HandoffFailed.reason`
: Why it failed, one of the reasons below. Read only.

`HandoffFailed.players`
: For `limit`, the player IDs of the people moved too often, so a retry can leave them out; empty otherwise. Read only.

`HandoffFailed.name`
: `"HandoffFailed"`.

## Description

`reason` is one of:

`players`
: None of the people was still connected.

`limit`
: The project is at its room limit, a person in the handoff was handed off 6 times in the last minute, or people from one client address 30 times.

`spending`
: The project is over its spending limit.

`unavailable`
: The new room couldn't be made, or the router didn't answer within 15 seconds.

`invalid`
: The request was refused; check the players and `to.type`.

`room.handoff()` rejects with a plain `Error` instead, sending nothing, for a bot, a player who isn't connected, or one whose client is too old.

## Examples

### Retrying without the people moved too often

```ts
// matchmaker.ts
import { defineRoom, HandoffFailed, isBot } from "@irtio/room";

export default defineRoom({
  async onMessage(room, _connection, message) {
    if (message !== "start") return;
    const people = [...room.presence].filter((p) => p.connected && !isBot(p.player)).map((p) => p.player);
    try {
      await room.handoff({ players: people, to: { type: "match" } });
    } catch (e) {
      if (!(e instanceof HandoffFailed) || e.reason !== "limit" || e.players.length === 0) throw e;
      const rest = people.filter((p) => !e.players.includes(p));
      if (rest.length > 0) await room.handoff({ players: rest, to: { type: "match" } });
    }
  },
});
```

## See also

- [From your own room code](/docs/room/guides/lobbies#from-your-own-room-code), in the lobbies guide
