

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?
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 aServerErrorwith 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 aServerErrorwith 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:
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 );
}