Show an error message on connection failures

Apparently this code has been broken ever since we migrated to
HTTPS.
This commit is contained in:
Guangcong Luo 2021-07-05 14:48:42 -04:00
parent 7a3783d1c8
commit 05b9b19dcc

View File

@ -732,8 +732,18 @@ function toId() {
var constructSocket = function () {
var protocol = (Config.server.port === 443 || Config.server.https) ? 'https' : 'http';
Config.server.host = $.trim(Config.server.host);
return new SockJS(protocol + '://' + Config.server.host + ':' +
Config.server.port + Config.sockjsprefix, [], {timeout: 5 * 60 * 1000});
try {
return new SockJS(
protocol + '://' + Config.server.host + ':' + Config.server.port + Config.sockjsprefix,
[], {timeout: 5 * 60 * 1000}
);
} catch (err) {
// The most common case this happens is if an HTTPS connection fails,
// and we fall back to HTTP, which throws a SecurityError if the URL
// is HTTPS
self.trigger('init:connectionerror');
return null;
}
};
this.socket = constructSocket();