OnAuth Return CustomData
-
Hi all,
The OnAuth method can only return the false value,right? What should I do if I want to return custom data after a validation failure?
Thanks.😁for example:
onAuth(client, options): Promise < any > { return new Promise((resolve, reject) => { let myData = { code: -1, reason: 'token is missing' } reject(myData); }); } //other test onAuth(client, options): Promise < any > { let myData={ code: -1, reason: 'token is missing' } return myData; } //and the client side client.joinOrCreate("test").then(room => { }).catch(err => { //the err is null str });
-
Hi @BlueBang, currently you can only throw an error containing a string to be able to catch in the client-side.
e.g.
onAuth(client, options) { // ... throw new Error("token is missing"); }
There are plans on supporting code + reason soon, though: https://github.com/colyseus/colyseus/issues/317
-
@endel yeah,Because it is still necessary to distinguish between system exceptions and business exceptions. My current solution is to add a formarter in the client-side.tanks for reply.😁