1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

Desktop: Only repeat failed requests up to 3 times during sync

This commit is contained in:
Laurent Cozic
2019-07-29 10:12:23 +02:00
parent af4aa01b75
commit 2c6b291b9b
2 changed files with 22 additions and 4 deletions

View File

@ -17,17 +17,27 @@ function requestCanBeRepeated(error) {
async function tryAndRepeat(fn, count) {
let retryCount = 0;
// Don't use internal fetch retry mechanim since we
// are already retrying here.
const shimFetchMaxRetryPrevious = shim.fetchMaxRetrySet(0);
const defer = () => {
shim.fetchMaxRetrySet(shimFetchMaxRetryPrevious);
}
while (true) {
try {
const result = await fn();
defer();
return result;
} catch (error) {
if (retryCount >= count) throw error;
if (!requestCanBeRepeated(error)) throw error;
if (retryCount >= count || !requestCanBeRepeated(error)) {
defer();
throw error;
}
retryCount++;
await time.sleep(1 + retryCount * 3);
}
}
}
}
class FileApi {