DataError
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe DataError class of the Room API is the error a PlayerData, Collection or 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
oncekey 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
versiongiven didn’t match. E_TYPEincrement()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
versionoronce.
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
// 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, in the player data guide
- Data calls, for the client’s side
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
DataError | 0.1 | 0.1 | 0.1 | 0.1 |