RoomCloseEvent: error property
Available since
@irtio/client 5.0BrowsersNodeThe error read-only property of the RoomCloseEvent interface is the IrtError that ended the connection, unless the client closed it itself.
Value
An IrtError or undefined.
- On a
closeevent, it’s theIrtErrorthat ended the connection, with the close code as itscode, or 0 when the first connection failed before any close. It’sundefinedwhen the client closed withclose(), whenwasCleanistrue. - On a
reconnectingevent, it’s alwaysundefined.
Description
The error’s name is one of the web’s error names, such as VersionError for 4004 or TimeoutError when the first connection took longer than timeout. When the client closes before it was ready, connect() and ready reject with the same error.
Examples
Reloading for a new build
A room build whose schema differs from the client’s closes the connection with 4004, a VersionError. Reloading the page fetches the client that matches it.
// new-build.ts
import { connect, reloadForNewBuild } from "@irtio/client";
const room = await connect("https://rooms.irt.io/my-game/arena");
room.addEventListener("close", ({ error }) => {
if (error?.name === "VersionError") reloadForNewBuild();
else if (error) console.error(`${error.name}: ${error.message}`);
});
Reload only on VersionError. The client already reconnects after the codes that allow it.
See also
IrtErrorreloadForNewBuild()- Errors and close codes, for every name and code
Runtime availability
| Browsers | Node | |
|---|---|---|
error | 5.0 | 5.0 |