# DataError

> The DataError class of the Room API is the error a player data, collection or leaderboard call rejects with.

The **`DataError`** class of the [Room API](/docs/room) is the error a [`PlayerData`](/docs/room/player-data), [`Collection`](/docs/room/collection) or [`Leaderboard`](/docs/room/leaderboard) call rejects with. It extends `Error`.

## Instance properties

`DataError.code`
: What went wrong, one of the codes below. Read only.

`DataError.message`
: The code, a colon, and a description, such as `E_VERSION: ...`.

`DataError.name`
: `"DataError"`.

## Description

`code` is one of:

`E_INVALID`
: A malformed call, one over a size limit, a `once` key used again with different arguments, or a bot's player ID.

`E_FORBIDDEN`
: The caller may not do it.

`E_UNKNOWN`
: The collection isn't declared in the live build, or it's the wrong kind for the call.

`E_VERSION`
: The `version` given didn't match.

`E_TYPE`
: `increment()` on a value that isn't a number.

`E_QUOTA`
: Over a player's 256 keys or 1 MB, or a collection's 1,000,000 entries.

`E_LIMIT`
: Over a rate limit, such as a room's 200 data calls a second or 64 at once.

`E_SPENDING`
: The project is over its spending limit, or out of credit.

`E_UNAVAILABLE`
: The data service couldn't be reached within the call's deadline. A write may or may not have happened, so repeat it with `version` or `once`.

`instanceof DataError` holds for errors from any copy of the SDK, such as one the room host made.

## Examples

### Retrying a write the data service didn't answer

```ts
// retry-coins.ts
import { DataError, defineRoom } from "@irtio/room";

export default defineRoom({
  async onMessage(room, connection, message) {
    if (message !== "daily-bonus") return;
    const day = new Date(room.now()).toISOString().slice(0, 10);
    for (let attempt = 0; attempt < 3; attempt++) {
      try {
        await room.playerData(connection.player).increment("coins", 10, { once: `bonus:${day}:${connection.player}` });
        return;
      } catch (e) {
        if (!(e instanceof DataError) || e.code !== "E_UNAVAILABLE") throw e;
      }
    }
  },
});
```

## See also

- [Errors](/docs/room/guides/player-data#errors), in the player data guide
- [Data calls](/docs/client/errors#data-calls), for the client's side
