Catch DOMException

This commit is contained in:
Tor Hveem 2014-05-06 21:48:40 +02:00
parent 9f6f598f40
commit d2f11ad89d
2 changed files with 13 additions and 1 deletions

View File

@ -45,6 +45,9 @@
<div class="alert alert-danger" ng-show="sslError">
<strong>Secure connection error</strong> A secure connection with the WeeChat relay could not be initiated. This is most likely because your browser does not trust your relay's certificate. Please read the encryption instructions below!
</div>
<div class="alert alert-danger" ng-show="securityError">
<strong>Secure connection error</strong> Unable to connect to unencrypted relay when your are connecting to Glowing Bear over HTTPS. Please use an encrypted relay or load the page without using HTTPS.
</div>
<div class="panel-group" id="accordion">
<div class="panel">
<div class="panel-heading">

View File

@ -242,6 +242,7 @@ function($rootScope,
var connect = function (host, port, passwd, ssl, noCompression) {
var proto = ssl ? 'wss' : 'ws';
var url = proto + "://" + host + ":" + port + "/weechat";
$log.debug('Connecting to URL: ', url);
var onopen = function () {
@ -375,7 +376,8 @@ function($rootScope,
};
ngWebsockets.connect(url,
try {
ngWebsockets.connect(url,
protocol,
{
'binaryType': "arraybuffer",
@ -384,6 +386,12 @@ function($rootScope,
'onmessage': onmessage,
'onerror': onerror
});
}catch(e) {
$log.debug("Websocket caught DOMException:", e);
$rootScope.lastError = Date.now();
$rootScope.errorMessage = true;
$rootScope.securityError = true;
}
};
@ -959,6 +967,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$scope.connect = function() {
$scope.requestNotificationPermission();
$rootScope.sslError = false;
$rootScope.securityError = false;
$rootScope.errorMessage = false;
connection.connect($scope.host, $scope.port, $scope.password, $scope.ssl);
};