Automatically retry failed http requests
If we failed to reach the server, wait a second and try again up to 3 times. // FREEBIE
This commit is contained in:
parent
a93b8cea72
commit
c062fe3060
2 changed files with 40 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue