Improve stack traces on HTTPErrors

Save stack even earlier, outside the promise.

// FREEBIE
pull/749/head
lilia 10 years ago
parent c062fe3060
commit 81ebc5ffd7

@ -38733,7 +38733,6 @@ var TextSecureServer = (function() {
function promise_ajax(url, options) { function promise_ajax(url, options) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
console.log(options.type, url); console.log(options.type, url);
var error = new Error(); // just in case, save stack here.
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open(options.type, url, true /*async*/); xhr.open(options.type, url, true /*async*/);
@ -38761,18 +38760,19 @@ var TextSecureServer = (function() {
resolve(result, xhr.status); resolve(result, xhr.status);
} else { } else {
console.log(options.type, url, xhr.status, 'Error'); console.log(options.type, url, xhr.status, 'Error');
reject(HTTPError(xhr.status, result, error.stack)); reject(HTTPError(xhr.status, result, options.stack));
} }
}; };
xhr.onerror = function() { xhr.onerror = function() {
console.log(options.type, url, xhr.status, 'Error'); console.log(options.type, url, xhr.status, 'Error');
reject(HTTPError(xhr.status, null, error.stack)); reject(HTTPError(xhr.status, null, options.stack));
}; };
xhr.send( options.data || null ); xhr.send( options.data || null );
}); });
} }
function ajax(url, options) { function ajax(url, options) {
options.stack = new Error().stack; // just in case, save stack here.
var count = 3; var count = 3;
function retry(e) { function retry(e) {

@ -9,7 +9,6 @@ var TextSecureServer = (function() {
function promise_ajax(url, options) { function promise_ajax(url, options) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
console.log(options.type, url); console.log(options.type, url);
var error = new Error(); // just in case, save stack here.
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open(options.type, url, true /*async*/); xhr.open(options.type, url, true /*async*/);
@ -37,18 +36,19 @@ var TextSecureServer = (function() {
resolve(result, xhr.status); resolve(result, xhr.status);
} else { } else {
console.log(options.type, url, xhr.status, 'Error'); console.log(options.type, url, xhr.status, 'Error');
reject(HTTPError(xhr.status, result, error.stack)); reject(HTTPError(xhr.status, result, options.stack));
} }
}; };
xhr.onerror = function() { xhr.onerror = function() {
console.log(options.type, url, xhr.status, 'Error'); console.log(options.type, url, xhr.status, 'Error');
reject(HTTPError(xhr.status, null, error.stack)); reject(HTTPError(xhr.status, null, options.stack));
}; };
xhr.send( options.data || null ); xhr.send( options.data || null );
}); });
} }
function ajax(url, options) { function ajax(url, options) {
options.stack = new Error().stack; // just in case, save stack here.
var count = 3; var count = 3;
function retry(e) { function retry(e) {

Loading…
Cancel
Save