diff --git a/app/js/controllers.js b/app/js/controllers.js index a29a2625..84bd2f9b 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -155,6 +155,15 @@ angular.module('myApp.controllers', []) }, function (error) { $scope.progress.enabled = false; switch (error.type) { + case 'NETWORK_BAD_REQUEST': + if (location.protocol == 'https:') { + ErrorService.confirm({type: 'HTTPS_MIXED_FAIL'}).then(function () { + location = location.toString().replace('/^https:/', 'http:'); + }); + error.handled = true; + } + break; + case 'PHONE_NUMBER_INVALID': $scope.error = {field: 'phone'}; error.handled = true; @@ -282,7 +291,7 @@ angular.module('myApp.controllers', []) } }) - .controller('AppImDialogsController', function ($scope, $location, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager) { + .controller('AppImDialogsController', function ($scope, $location, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager, ErrorService) { // console.log('init controller'); @@ -374,6 +383,15 @@ angular.module('myApp.controllers', []) } }, function (error) { + if (error.type == 'NETWORK_BAD_REQUEST') { + if (location.protocol == 'https:') { + ErrorService.confirm({type: 'HTTPS_MIXED_FAIL'}).then(function () { + location = location.toString().replace('/^https:/', 'http:'); + }); + error.handled = true; + } + } + if (error.code == 401) { MtpApiManager.logOut()['finally'](function () { $location.url('/login'); diff --git a/app/js/lib/mtproto.js b/app/js/lib/mtproto.js index 2cf91869..7c6a68a0 100644 --- a/app/js/lib/mtproto.js +++ b/app/js/lib/mtproto.js @@ -1196,14 +1196,25 @@ factory('MtpAuthorizer', function (MtpDcConfigurator, MtpRsaKeysManager, MtpSecu transformResponse: function (responseBuffer) { var deserializer = new TLDeserialization(responseBuffer, {mtproto: true}); - var auth_key_id = deserializer.fetchLong('auth_key_id'); - var msg_id = deserializer.fetchLong('msg_id'); - var msg_len = deserializer.fetchInt('msg_len'); + try { + + var auth_key_id = deserializer.fetchLong('auth_key_id'); + var msg_id = deserializer.fetchLong('msg_id'); + var msg_len = deserializer.fetchInt('msg_len'); + + } catch (e) { + return $q.reject({code: 406, type: 'NETWORK_BAD_RESPONSE', problem: e.message, stack: e.stack}); + } rng_seed_time(); return deserializer; } + })['catch'](function (error) { + if (!error.message && !error.type) { + error = {code: 406, type: 'NETWORK_BAD_REQUEST'}; + } + return $q.reject(error); }); }; @@ -2189,6 +2200,11 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato return $http.post('http://' + MtpDcConfigurator.chooseServer(self.dcID) + '/apiw1', resultArray, { responseType: 'arraybuffer', transformRequest: null + })['catch'](function (error) { + if (!error.message && !error.type) { + error = {code: 406, type: 'NETWORK_BAD_REQUEST'}; + } + return $q.reject(error); }); }); }; diff --git a/app/partials/confirm_modal.html b/app/partials/confirm_modal.html index b9c21dee..3a6efff9 100644 --- a/app/partials/confirm_modal.html +++ b/app/partials/confirm_modal.html @@ -9,6 +9,11 @@ A new version of Webogram is available. Load it? Are you sure? This can not be undone! Are you sure you want to log out all devices except for the current one? + + Your browser does not support mixed content which is neccessary for MTProto support on https. Learn more →
+ Would you like use http-version instead? +
+ diff --git a/app/partials/error_modal.html b/app/partials/error_modal.html index 3ff695bf..51fdd734 100644 --- a/app/partials/error_modal.html +++ b/app/partials/error_modal.html @@ -10,6 +10,7 @@ Unauthorized Access denied Not found + Network error Too fast Server error @@ -20,6 +21,12 @@