TLSyncErrorCloseEventReason

See source code

Predefined reasons for server-initiated connection closures. These constants represent different error conditions that can cause the sync server to terminate a WebSocket connection.

TLSyncErrorCloseEventReason: {
  readonly RATE_LIMITED: "RATE_LIMITED";
  readonly CLIENT_TOO_OLD: "CLIENT_TOO_OLD";
  readonly INVALID_RECORD: "INVALID_RECORD";
  readonly ROOM_FULL: "ROOM_FULL";
  readonly NOT_FOUND: "NOT_FOUND";
  readonly SERVER_TOO_OLD: "SERVER_TOO_OLD";
  readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
  readonly NOT_AUTHENTICATED: "NOT_AUTHENTICATED";
  readonly FORBIDDEN: "FORBIDDEN";
};

Example

// Server usage
if (!user.hasPermission(roomId)) {
  socket.close(
    TLSyncErrorCloseEventCode,
    TLSyncErrorCloseEventReason.FORBIDDEN,
  );
}

// Client error handling
syncClient.onSyncError((reason) => {
  switch (reason) {
    case TLSyncErrorCloseEventReason.NOT_FOUND:
      showError("Room does not exist");
      break;
    case TLSyncErrorCloseEventReason.FORBIDDEN:
      showError("Access denied");
      break;
    case TLSyncErrorCloseEventReason.CLIENT_TOO_OLD:
      showError("Please update your app");
      break;
  }
});
Prev
TLSyncErrorCloseEventCode
Next
allDefaultFontFaces