Skip to content

Commit

Permalink
Handle immediate connection errors
Browse files Browse the repository at this point in the history
The browser might throw an exception right away if there is something it
doesn't like with our connect attempt. E.g. using a non-TLS WebSocket
from a TLS web page.
  • Loading branch information
CendioOssman committed Dec 5, 2023
1 parent 7d2dad0 commit 9ac632d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,18 @@ const UI = {
}
url += '/' + path;

UI.rfb = new RFB(document.getElementById('noVNC_container'), url,
{ shared: UI.getSetting('shared'),
repeaterID: UI.getSetting('repeaterID'),
credentials: { password: password } });
try {
UI.rfb = new RFB(document.getElementById('noVNC_container'), url,
{ shared: UI.getSetting('shared'),
repeaterID: UI.getSetting('repeaterID'),
credentials: { password: password } });
} catch (exc) {
Log.Error("Failed to connect to server: " + exc);
UI.updateVisualState('disconnected');
UI.showStatus(_("Failed to connect to server: ") + exc, 'error');
return;
}

UI.rfb.addEventListener("connect", UI.connectFinished);
UI.rfb.addEventListener("disconnect", UI.disconnectFinished);
UI.rfb.addEventListener("serververification", UI.serverVerify);
Expand Down

0 comments on commit 9ac632d

Please sign in to comment.