1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Improved network error handling

This commit is contained in:
Laurent Cozic
2017-10-15 12:13:09 +01:00
parent 65ab55c031
commit 3d8327ae0b
7 changed files with 350 additions and 349 deletions

View File

@@ -158,6 +158,8 @@ class OneDriveApi {
if (data) options.body = data;
options.timeout = 1000 * 60 * 5; // in ms
for (let i = 0; i < 5; i++) {
options.headers['Authorization'] = 'bearer ' + this.token();
@@ -171,13 +173,25 @@ class OneDriveApi {
response = await shim.fetchBlob(url, options);
}
} catch (error) {
let canRetry = true;
if (error.message == 'Network request failed') {
// Unfortunately the error 'Network request failed' doesn't have a type
// or error code, so hopefully that message won't change and is not localized
this.logger().info('Got error "Network request failed" - retrying (' + i + ')...');
} else if (error.code == 'ECONNRESET') {
// request to https://public-ch3302....1fab24cb1bd5f.md failed, reason: socket hang up"
} else if (error.message.indexOf('network timeout') === 0) {
// network timeout at: https://public-ch3302...859f9b0e3ab.md
} else {
canRetry = false;
}
if (canRetry) {
this.logger().info('Got error code ' + error.code + ': ' + error.message + ' - retrying (' + i + ')...');
await time.sleep((i + 1) * 3);
continue;
} else {
this.logger().error('Got unhandled error:', error ? error.code : '', error ? error.message : '', error);
throw error;
}
}