IrtError: name property

Available since @irtio/client 5.0BrowsersNode

The name read-only property of the IrtError interface is one of the web’s error names for what went wrong, the ones fetch(), WebSocket and the DOM use.

Value

A string, one of:

AbortError
A signal aborted a connect, a call or a request, with code 0 and the signal’s reason as cause; or close() was called before the client was ready, with code 1000.
TimeoutError
A connect or a call timed out, or a signal from AbortSignal.timeout() aborted one, with code 0.
NetworkError
The router couldn’t be reached, or the connection dropped before a call’s answer, with code 0.
NotSupportedError
The router doesn’t support the client’s protocol version, or the room isn’t of the client’s room type or the live build has no such type: codes 4000 and 4015. The runtime has no global WebSocket, as Node before 24: code 0.
NotAllowedError
The player’s token was refused, they were kicked or they’re banned: codes 4001, 4006, 4013 and 4014, and HTTP statuses 401 and 403.
NotFoundError
The room or the join code doesn’t exist: code 4002 and HTTP status 404.
QuotaExceededError
A limit was reached: codes 4003 and 4009, and HTTP status 429.
VersionError
The client’s schema differs from the room build’s: code 4004. A site client reloads with reloadForNewBuild().
InvalidStateError
The room hibernated by its own request (4011), the same player connected elsewhere (4012) or the client was used before it was ready or after it closed (0).
OperationError
The room stopped (4007), a call failed in the room (422) or a room-wide request failed with any other HTTP status.

Description

Branch on name first, as for a web API’s errors, and on code where one name covers several causes. Never branch on message.

Examples

Retrying a call that got no answer

A shop retries a purchase once when the room didn’t answer in time. The purchase carries an order ID the room checks, so a purchase that did run isn’t made twice.

// buy.ts
import { call, connect, defineCalls, defineSchema, IrtError } from "@irtio/client";

const schema = defineSchema({ calls: defineCalls({ buy: call({ item: "string", order: "string" }) }) });
const room = await connect("shop", { schema });

export async function buy(item: string) {
  const order = crypto.randomUUID();
  try {
    return await room.calls.buy({ item, order });
  } catch (e) {
    if (e instanceof IrtError && e.name === "TimeoutError") return room.calls.buy({ item, order });
    throw e;
  }
}

See also

Runtime availability

BrowsersNode
name5.05.0