diff --git a/app/js/lib/mtproto.js b/app/js/lib/mtproto.js index b404ecc4..965a15a3 100644 --- a/app/js/lib/mtproto.js +++ b/app/js/lib/mtproto.js @@ -201,6 +201,10 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) responseType: 'arraybuffer', transformRequest: null, transformResponse: function (responseBuffer) { + if (!responseBuffer || !responseBuffer.byteLength) { + return $q.reject({code: 406, type: 'NETWORK_BAD_RESPONSE'}); + } + try { var deserializer = new TLDeserialization(responseBuffer, {mtproto: true}); @@ -216,20 +220,12 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) return deserializer; } - }).then( - function (result) { - if (!result.data || !result.data.byteLength) { - return $q.reject({code: 406, type: 'NETWORK_BAD_REQUEST'}); - } - return result; - }, - function (error) { - if (!error.message && !error.type) { - error = {code: 406, type: 'NETWORK_BAD_REQUEST'}; - } - return $q.reject(error); + })['catch'](function (error) { + if (!error.message && !error.type) { + error = {code: 406, type: 'NETWORK_BAD_REQUEST'}; } - ); + return $q.reject(error); + }); }; function mtpSendReqPQ (auth) { @@ -1130,7 +1126,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) }).then( function (result) { if (!result.data || !result.data.byteLength) { - return $q.reject({code: 406, type: 'NETWORK_BAD_REQUEST'}); + return $q.reject({code: 406, type: 'NETWORK_BAD_RESPONSE'}); } return result; },