auth: Make more resilant to backend failures
This commit is contained in:
@@ -25,12 +25,14 @@ export default class AuthManager {
|
||||
})
|
||||
});
|
||||
|
||||
// Make sure the fetch returned okay
|
||||
if(!response.ok)
|
||||
throw new Error(`Failed to query quth server: ${response.statusText}`)
|
||||
|
||||
let json = (await response.json()) as JoinResponse;
|
||||
|
||||
if (!json.success) {
|
||||
this.logger.Error(`Failed to query auth server: ${json.error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!json.success)
|
||||
throw new Error(json.error);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -294,11 +294,12 @@ export default class WSServer {
|
||||
client.sendMsg(guacutils.encode('login', '0', 'You must connect to the VM before logging in.'));
|
||||
return;
|
||||
}
|
||||
var res = await this.auth!.Authenticate(msgArr[1], client);
|
||||
try {
|
||||
let res = await this.auth!.Authenticate(msgArr[1], client);
|
||||
if (res.clientSuccess) {
|
||||
this.logger.Info(`${client.IP.address} logged in as ${res.username}`);
|
||||
client.sendMsg(guacutils.encode('login', '1'));
|
||||
var old = this.clients.find((c) => c.username === res.username);
|
||||
let old = this.clients.find((c) => c.username === res.username);
|
||||
if (old) {
|
||||
// kick() doesnt wait until the user is actually removed from the list and itd be anal to make it do that
|
||||
// so we call connectionClosed manually here. When it gets called on kick(), it will return because the user isn't in the list
|
||||
@@ -321,6 +322,11 @@ export default class WSServer {
|
||||
client.kick();
|
||||
}
|
||||
}
|
||||
} catch(err) {
|
||||
this.logger.Error(`Error authenticating client ${client.IP.address}: ${(err as Error).message}`);
|
||||
// for now?
|
||||
client.sendMsg(guacutils.encode('login', '0', 'There was an internal error while authenticating. Please let a staff member know as soon as possible'))
|
||||
}
|
||||
break;
|
||||
case 'list':
|
||||
client.sendMsg(guacutils.encode('list', this.Config.collabvm.node, this.Config.collabvm.displayname, this.screenHidden ? this.screenHiddenThumb : await this.getThumbnail()));
|
||||
@@ -915,7 +921,10 @@ export default class WSServer {
|
||||
|
||||
async getThumbnail(): Promise<string> {
|
||||
let display = this.VM.GetDisplay();
|
||||
if (!display.Connected()) throw new Error('VM display is not connected');
|
||||
|
||||
// oh well
|
||||
if (!display.Connected())
|
||||
return "";
|
||||
|
||||
let buf = await JPEGEncoder.EncodeThumbnail(display.Buffer(), display.Size());
|
||||
return buf.toString('base64');
|
||||
|
||||
Reference in New Issue
Block a user