1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Electron: partially resolves #532: Better handling of Dropbox error message

This commit is contained in:
Laurent Cozic 2018-05-21 16:24:57 +01:00
parent fd77671575
commit ed70cf571c
2 changed files with 11 additions and 6 deletions

View File

@ -196,7 +196,7 @@ class DropboxApi {
return loadResponseJson();
} catch (error) {
tryCount++;
if (error.code.indexOf('too_many_write_operations') >= 0) {
if (error && error.code && error.code.indexOf('too_many_write_operations') >= 0) {
this.logger().warn('too_many_write_operations ' + tryCount);
if (tryCount >= 3) {
throw error;

View File

@ -22,6 +22,11 @@ class FileApiDriverDropbox {
return '/' + path;
}
hasErrorCode_(error, errorCode) {
if (!error || !error.code) return false;
return error.code.indexOf(errorCode) >= 0;
}
async stat(path) {
try {
const metadata = await this.api().exec('POST', 'files/get_metadata', {
@ -30,7 +35,7 @@ class FileApiDriverDropbox {
return this.metadataToStat_(metadata, path);
} catch (error) {
if (error.code.indexOf('not_found') >= 0) {
if (this.hasErrorCode_(error, 'not_found')) {
// ignore
} else {
throw error;
@ -83,7 +88,7 @@ class FileApiDriverDropbox {
} catch (error) {
// If there's an error related to an invalid cursor, clear the cursor and retry.
if (cursor) {
if (error.httpStatus === 400 || error.code.indexOf('reset') >= 0) {
if ((error && error.httpStatus === 400) || this.hasErrorCode_(error, 'reset')) {
// console.info('Clearing cursor and retrying', error);
cursor = null;
continue;
@ -126,7 +131,7 @@ class FileApiDriverDropbox {
}, options);
return response;
} catch (error) {
if (error.code.indexOf('not_found') >= 0) {
if (this.hasErrorCode_(error, 'not_found')) {
return null;
} else {
throw error;
@ -140,7 +145,7 @@ class FileApiDriverDropbox {
path: this.makePath_(path),
});
} catch (error) {
if (error.code.indexOf('path/conflict') >= 0) {
if (this.hasErrorCode_(error, 'path/conflict')) {
// Ignore
} else {
throw error;
@ -166,7 +171,7 @@ class FileApiDriverDropbox {
path: this.makePath_(path),
});
} catch (error) {
if (error.code.indexOf('not_found') >= 0) {
if (this.hasErrorCode_(error, 'not_found')) {
// ignore
} else {
throw error;