From fb2a80fc1434509488f2f00c3388176a699aa5f7 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 15 Oct 2014 17:05:24 +0400 Subject: [PATCH] Handling exceptions in http.post (for SSL errors) --- app/js/lib/mtproto.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/js/lib/mtproto.js b/app/js/lib/mtproto.js index 219a63af..a880046f 100644 --- a/app/js/lib/mtproto.js +++ b/app/js/lib/mtproto.js @@ -197,10 +197,16 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) resultArray = resultArray.buffer; } - return $http.post('http://' + MtpDcConfigurator.chooseServer(dcID) + '/apiw1', resultArray, { - responseType: 'arraybuffer', - transformRequest: null - }).then( + var requestPromise; + try { + requestPromise = $http.post('http://' + MtpDcConfigurator.chooseServer(dcID) + '/apiw1', resultArray, { + responseType: 'arraybuffer', + transformRequest: null + }); + } catch (e) { + requestPromise = $q.reject(e); + } + return requestPromise.then( function (result) { if (!result.data || !result.data.byteLength) { return $q.reject({code: 406, type: 'NETWORK_BAD_RESPONSE'}); @@ -1119,10 +1125,16 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) resultArray = resultArray.buffer; } - return $http.post('http://' + MtpDcConfigurator.chooseServer(self.dcID) + '/apiw1', resultArray, { - responseType: 'arraybuffer', - transformRequest: null - }).then( + var requestPromise; + try { + requestPromise = $http.post('http://' + MtpDcConfigurator.chooseServer(self.dcID) + '/apiw1', resultArray, { + responseType: 'arraybuffer', + transformRequest: null + }); + } catch (e) { + requestPromise = $q.reject(e); + } + return requestPromise.then( function (result) { if (!result.data || !result.data.byteLength) { return $q.reject({code: 406, type: 'NETWORK_BAD_RESPONSE'});