Browse Source

Improve error reporting when network request fails

master
Igor Zhukov 9 years ago
parent
commit
ecb4871723
  1. 23
      app/js/lib/mtproto.js
  2. 2
      app/js/lib/mtproto_wrapper.js
  3. 1
      app/partials/desktop/error_modal.html

23
app/js/lib/mtproto.js

@ -208,18 +208,20 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) @@ -208,18 +208,20 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
var requestData = xhrSendBuffer ? resultBuffer : resultArray,
requestPromise;
var url = MtpDcConfigurator.chooseServer(dcID);
var baseError = {code: 406, type: 'NETWORK_BAD_RESPONSE', url: url};
try {
requestPromise = $http.post(MtpDcConfigurator.chooseServer(dcID), requestData, {
requestPromise = $http.post(url, requestData, {
responseType: 'arraybuffer',
transformRequest: null
});
} catch (e) {
requestPromise = $q.reject({code: 406, type: 'NETWORK_BAD_RESPONSE', originalError: e});
requestPromise = $q.reject(angular.extend(baseError, {originalError: e}));
}
return requestPromise.then(
function (result) {
if (!result.data || !result.data.byteLength) {
return $q.reject({code: 406, type: 'NETWORK_BAD_RESPONSE'});
return $q.reject(baseError);
}
try {
@ -230,14 +232,14 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) @@ -230,14 +232,14 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
var msg_len = deserializer.fetchInt('msg_len');
} catch (e) {
return $q.reject({code: 406, type: 'NETWORK_BAD_RESPONSE', originalError: e});
return $q.reject(angular.extend(baseError, {originalError: e}));
}
return deserializer;
},
function (error) {
if (!error.message && !error.type) {
error = {code: 406, type: 'NETWORK_BAD_REQUEST', originalError: error};
error = angular.extend(baseError, {originalError: error});
}
return $q.reject(error);
}
@ -286,7 +288,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) @@ -286,7 +288,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
deferred.reject(error);
});
}, function (error) {
console.log(dT(), 'req_pq error', error.message);
console.error(dT(), 'req_pq error', error.message);
deferred.reject(error);
});
@ -1201,19 +1203,22 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) @@ -1201,19 +1203,22 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
var requestData = xhrSendBuffer ? request.getBuffer() : request.getArray();
var requestPromise;
var url = MtpDcConfigurator.chooseServer(self.dcID, self.upload);
var baseError = {code: 406, type: 'NETWORK_BAD_RESPONSE', url: url};
try {
options = angular.extend(options || {}, {
responseType: 'arraybuffer',
transformRequest: null
});
requestPromise = $http.post(MtpDcConfigurator.chooseServer(self.dcID, self.upload), requestData, options);
requestPromise = $http.post(url, requestData, options);
} 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'});
return $q.reject(baseError);
}
return result;
},
@ -1228,7 +1233,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) @@ -1228,7 +1233,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
});
}
if (!error.message && !error.type) {
error = {code: 406, type: 'NETWORK_BAD_REQUEST'};
error = angular.extend(baseError, {type: 'NETWORK_BAD_REQUEST', originalError: error});
}
return $q.reject(error);
}

2
app/js/lib/mtproto_wrapper.js

@ -216,7 +216,7 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto']) @@ -216,7 +216,7 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
networker.wrapApiCall(method, params, options).then(function (result) {
deferred.resolve(result);
}, rejectPromise);
});
}, rejectPromise);
}
}
else if (!options.rawError && error.code == 420) {

1
app/partials/desktop/error_modal.html

@ -63,6 +63,7 @@ @@ -63,6 +63,7 @@
<div ng-if="error" class="error_modal_details" ng-switch="error.detailsShown">
<textarea ng-switch-when="true" rows="3" onclick="this.select()">Method: {{error.input || 'N/A'}}
Url: {{error.url || 'N/A'}}
Result: {{error.originalError ? error.originalError : (error.stack ? (error.name || '') + ' ' + (error.description || error.message) : error)}}
Stack: {{error.originalError.stack || error.stack}}</textarea>
<div ng-switch-default>

Loading…
Cancel
Save