diff --git a/js/libtextsecure.js b/js/libtextsecure.js index e996a4e12..f1a5c698d 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38730,7 +38730,7 @@ var TextSecureServer = (function() { 'use strict'; // Promise-based async xhr routine - function ajax(url, options) { + function promise_ajax(url, options) { return new Promise(function (resolve, reject) { console.log(options.type, url); var error = new Error(); // just in case, save stack here. @@ -38772,6 +38772,25 @@ var TextSecureServer = (function() { }); } + function ajax(url, options) { + var count = 3; + + function retry(e) { + if (e.name === 'HTTPError' && e.code === -1 && count > 0) { + count = count - 1; + return new Promise(function(resolve) { + setTimeout(function() { + resolve(promise_ajax(url, options).catch(retry)); + }, 1000 ); + }); + } else { + throw e; + } + } + + return promise_ajax(url, options).catch(retry); + } + function HTTPError(code, response, stack) { if (code > 999 || code < 100) { code = -1; diff --git a/libtextsecure/api.js b/libtextsecure/api.js index 2ec7f993a..941229f6b 100644 --- a/libtextsecure/api.js +++ b/libtextsecure/api.js @@ -6,7 +6,7 @@ var TextSecureServer = (function() { 'use strict'; // Promise-based async xhr routine - function ajax(url, options) { + function promise_ajax(url, options) { return new Promise(function (resolve, reject) { console.log(options.type, url); var error = new Error(); // just in case, save stack here. @@ -48,6 +48,25 @@ var TextSecureServer = (function() { }); } + function ajax(url, options) { + var count = 3; + + function retry(e) { + if (e.name === 'HTTPError' && e.code === -1 && count > 0) { + count = count - 1; + return new Promise(function(resolve) { + setTimeout(function() { + resolve(promise_ajax(url, options).catch(retry)); + }, 1000 ); + }); + } else { + throw e; + } + } + + return promise_ajax(url, options).catch(retry); + } + function HTTPError(code, response, stack) { if (code > 999 || code < 100) { code = -1;