IrtError: code property
Available since
@irtio/client 5.0BrowsersNodeThe code read-only property of the IrtError interface is the number behind the error: a close code, an HTTP status or 0 when there was none.
Value
A number, one of:
- 4000 to 4099
- The router or the room closed the connection with this close code, one the client doesn’t reconnect after. The
CloseCodeexport names them, and Close codes lists each one’s causes. - 1000
close()was called before the client was ready.- 422
- A call the room answered with an error, such as a handler that threw
CallRejected, or args that don’t match the call’s fields. - 400 to 599
createRoom(),joinByCode(),listPublic()orquickJoin()failed with this HTTP status.- 0
- There was no close code: the router couldn’t be reached, a timeout passed, a
signalaborted, a call got no answer from the room or the client was used before it was ready or after it closed.
Description
code is the detail behind name. Use it where one name covers several causes, such as InvalidStateError, which is both 4011, a room that hibernated by its own request, and 4012, the same player connecting elsewhere. IrtError isn’t a DOMException, whose own numeric code means something else.
Examples
Offering a rejoin after the room hibernated
A room that asks to hibernate with players connected closes their connections with 4011. The client doesn’t reconnect after it, so the game offers a button that connects again, which wakes the room.
// rejoin.ts
import { CloseCode, type ReadyRoomClient } from "@irtio/client";
export function offerRejoin(room: ReadyRoomClient, rejoin: () => void) {
room.addEventListener("close", ({ error }) => {
if (error?.code !== CloseCode.RoomHibernated) return;
const button = document.createElement("button");
button.textContent = "Rejoin";
button.addEventListener("click", rejoin, { once: true });
document.body.append(button);
});
}
See also
Runtime availability
| Browsers | Node | |
|---|---|---|
code | 5.0 | 5.0 |