Colyseus: How can I get specific authorization failure information after failing to enter the room in the room list?

Created on 28 Aug 2020  ยท  5Comments  ยท  Source: colyseus/colyseus

image
image

I created a room with client A, waiting for other players to join, and this room has some permission restrictions, such as gold or level, but now, I use client B to request the current room list. The room created by client A was found in the list, and client B requested to join at this time, but client B cannot enter because of insufficient permissions. How should I get the authorization failure information on client B? The prompt is to listen for onError in the room, but now the room obtained through getAvailableRooms does not provide an onError handle? (The room obtained in the callback after client A successfully creates the room has onError, onMessage... etc. listening handles) What should I do to get the authorization from client B because of insufficient gold coins The failed message?

โ“ question

All 5 comments

Hi @smallcoderofme,

During onAuth() you may throw a ServerError with a code + message - they're going to be available in the client-side in your catch block:

import { ServerError } from "colyseus";

onAuth(client, options, req) {
  throw new ServerError(401, "permission XYZ required");
}

Client-side:

async function connect() {
  try {
    const room = await client.joinById("THEROOMID", {...});

  } catch (e) {
    e.code // 401
    e.message // permission XYZ required
  }
}

Hope this helps. Cheers!

Hi @smallcoderofme,

During onAuth() you may throw a ServerError with a code + message - they're going to be available in the client-side in your catch block:

import { ServerError } from "colyseus";

onAuth(client, options, req) {
  throw new ServerError(401, "permission XYZ required");
}

Client-side:

async function connect() {
  try {
    const room = await client.joinById("THEROOMID", {...});

  } catch (e) {
    e.code // 401
    e.message // permission XYZ required
  }
}

Hope this helps. Cheers!

Works, thanks for your reply!

Hi @smallcoderofme,

During onAuth() you may throw a ServerError with a code + message - they're going to be available in the client-side in your catch block:

import { ServerError } from "colyseus";

onAuth(client, options, req) {
  throw new ServerError(401, "permission XYZ required");
}

Client-side:

async function connect() {
  try {
    const room = await client.joinById("THEROOMID", {...});

  } catch (e) {
    e.code // 401
    e.message // permission XYZ required
  }
}

Hope this helps. Cheers!

Hey @endel I think is need to change console.error to console.warn, because ReactNative catch the console.error and gives error screen, so you can't process error message.

Hi @vitalyrotari, thanks for letting me know - I've created two new builds with this change for the colyseus.js client:

  • 0.13.2
  • 0.14.0-alpha.10 (recommended, it's not out of "alpha" just yet, but seems very stable!)

It's undocumented for the unity client. But if i'm right your can catch it with
c# try { _room = await _client.JoinOrCreate<Session>( "myroom" ); } catch(MatchMakeException mme) { Debug.Log( "Error joining: " + mme.Code ); }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

endel picture endel  ยท  5Comments

HeadClot picture HeadClot  ยท  8Comments

BjoernRave picture BjoernRave  ยท  6Comments

gioragutt picture gioragutt  ยท  8Comments

DenisNP picture DenisNP  ยท  5Comments