Log all http requests at start and end

// FREEBIE
This commit is contained in:
lilia 2015-09-16 23:45:01 -07:00
parent 0017f196ef
commit 537f0ceef0
2 changed files with 8 additions and 0 deletions

View file

@ -38931,6 +38931,7 @@ TextSecureServer = function () {
*/ */
function ajax(url, options) { function ajax(url, options) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
console.log(options.type, url);
var error = new Error(); // just in case, save stack here. 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*/);
@ -38955,12 +38956,15 @@ TextSecureServer = function () {
try { result = JSON.parse(xhr.responseText + ''); } catch(e) {} try { result = JSON.parse(xhr.responseText + ''); } catch(e) {}
} }
if ( 0 <= xhr.status && xhr.status < 400) { if ( 0 <= xhr.status && xhr.status < 400) {
console.log('Success', xhr.status);
resolve(result, xhr.status); resolve(result, xhr.status);
} else { } else {
console.log('Error', xhr.status);
reject(HTTPError(xhr.status, result, error.stack)); reject(HTTPError(xhr.status, result, error.stack));
} }
}; };
xhr.onerror = function() { xhr.onerror = function() {
console.log('Error', xhr.status);
reject(HTTPError(xhr.status, null, error.stack)); reject(HTTPError(xhr.status, null, error.stack));
}; };
xhr.send( options.data || null ); xhr.send( options.data || null );

View file

@ -42,6 +42,7 @@ TextSecureServer = function () {
*/ */
function ajax(url, options) { function ajax(url, options) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
console.log(options.type, url);
var error = new Error(); // just in case, save stack here. 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*/);
@ -66,12 +67,15 @@ TextSecureServer = function () {
try { result = JSON.parse(xhr.responseText + ''); } catch(e) {} try { result = JSON.parse(xhr.responseText + ''); } catch(e) {}
} }
if ( 0 <= xhr.status && xhr.status < 400) { if ( 0 <= xhr.status && xhr.status < 400) {
console.log('Success', xhr.status);
resolve(result, xhr.status); resolve(result, xhr.status);
} else { } else {
console.log('Error', xhr.status);
reject(HTTPError(xhr.status, result, error.stack)); reject(HTTPError(xhr.status, result, error.stack));
} }
}; };
xhr.onerror = function() { xhr.onerror = function() {
console.log('Error', xhr.status);
reject(HTTPError(xhr.status, null, error.stack)); reject(HTTPError(xhr.status, null, error.stack));
}; };
xhr.send( options.data || null ); xhr.send( options.data || null );