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

Better handling of network errors

This commit is contained in:
Laurent Cozic 2017-07-30 22:22:57 +02:00
parent ad1fbba78d
commit 242b6dbff8
6 changed files with 34 additions and 23 deletions

View File

@ -72,7 +72,7 @@ class NoteItemComponent extends Component {
const listItemStyle = !!Number(note.is_todo) && checkboxChecked ? styles.listItemFadded : styles.listItem;
return (
<TouchableHighlight style={{borderWidth:1, borderColor:'red'}} onPress={() => this.onPress()} underlayColor="#0066FF">
<TouchableHighlight onPress={() => this.onPress()} underlayColor="#0066FF">
<View style={ listItemStyle }>
<Checkbox
style={checkboxStyle}

View File

@ -112,7 +112,14 @@ class SideMenuContentComponent extends Component {
return;
}
const sync = await reg.synchronizer(Setting.value('sync.target'))
let sync = null;
try {
sync = await reg.synchronizer(Setting.value('sync.target'))
} catch (error) {
reg.logger().info('Could not acquire synchroniser:');
reg.logger().info(error);
return;
}
if (this.props.syncStarted) {
sync.cancel();

View File

@ -69,8 +69,8 @@ class OneDriveApi {
}
async appDirectory() {
let r = await this.execJson('GET', '/drive/special/approot');
return r.parentReference.path + '/' + r.name;
let r = await this.execJson('GET', '/drive/special/approot');
return r.parentReference.path + '/' + r.name;
}
authCodeUrl(redirectUri) {
@ -172,8 +172,7 @@ class OneDriveApi {
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().warn('Got error below - retrying...');
this.logger().warn(error);
this.logger().info('Got error "Network request failed" - retrying (' + i + ')...');
await time.sleep((i + 1) * 3);
continue;
} else {
@ -204,8 +203,8 @@ class OneDriveApi {
// type: 'system',
// errno: 'EAGAIN',
// code: 'EAGAIN' }
this.logger().warn('Got error below - retrying...');
this.logger().warn(error);
this.logger().info('Got error below - retrying (' + i + ')...');
this.logger().info(error);
await time.sleep((i + 1) * 3);
continue;
} else if (error.code == 'itemNotFound' && method == 'DELETE') {

View File

@ -126,19 +126,25 @@ reg.scheduleSync = async (delay = null) => {
return;
}
const sync = await reg.synchronizer(syncTargetId);
let context = Setting.value('sync.context');
context = context ? JSON.parse(context) : {};
try {
let newContext = await sync.start({ context: context });
Setting.setValue('sync.context', JSON.stringify(newContext));
} catch (error) {
if (error.code == 'alreadyStarted') {
reg.logger().info(error.message);
} else {
throw error;
const sync = await reg.synchronizer(syncTargetId);
let context = Setting.value('sync.context');
context = context ? JSON.parse(context) : {};
try {
let newContext = await sync.start({ context: context });
Setting.setValue('sync.context', JSON.stringify(newContext));
} catch (error) {
if (error.code == 'alreadyStarted') {
reg.logger().info(error.message);
} else {
throw error;
}
}
} catch (error) {
reg.logger().info('Could not run background sync: ');
reg.logger().info(error);
}
reg.setupRecurrentSync();

View File

@ -55,7 +55,7 @@ class Synchronizer {
if (report.updateRemote) lines.push(_('Updated remote items: %d.', report.updateRemote));
if (report.deleteLocal) lines.push(_('Deleted local items: %d.', report.deleteLocal));
if (report.deleteRemote) lines.push(_('Deleted remote items: %d.', report.deleteRemote));
if (report.state) lines.push(_('State: %s.', report.state.replace(/_/g, ' ')));
if (!report.completedTime && report.state) lines.push(_('State: %s.', report.state.replace(/_/g, ' ')));
if (report.errors && report.errors.length) lines.push(_('Last error: %s (stacktrace in log).', report.errors[report.errors.length-1].message));
if (report.cancelling && !report.completedTime) lines.push(_('Cancelling...'));
if (report.completedTime) lines.push(_('Completed: %s', time.unixMsToLocalDateTime(report.completedTime)));
@ -464,7 +464,6 @@ class Synchronizer {
this.cancelling_ = false;
}
this.progressReport_.completedTime = time.unixMs();
this.logSyncOperation('finished', null, null, 'Synchronisation finished [' + synchronizationId + ']');
@ -475,7 +474,7 @@ class Synchronizer {
this.progressReport_ = {};
this.dispatch({ type: 'SYNC_COMPLETED' });
this.state_ = 'idle';
return outputContext;

View File

@ -508,7 +508,7 @@ async function initialize(dispatch, backButtonHandler) {
reg.setupRecurrentSync();
if (Setting.value('env') == 'dev') {
// reg.scheduleSync();
} else {
reg.scheduleSync();
}