Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

sync: move try-catch out of needsSyncing and handle errors in fullSync #207

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions src/services/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ export class SyncService implements SyncServiceAbstraction {
}

const now = new Date();
const needsSyncResult = await this.needsSyncing(forceSync);
const needsSync = needsSyncResult[0];
const skipped = needsSyncResult[1];

if (skipped) {
return this.syncCompleted(false);
var needsSync = false;
try {
needsSync = await this.needsSyncing(forceSync);
} catch (e) {
if (allowThrowOnError) {
throw e;
}
}

if (!needsSync) {
Expand Down Expand Up @@ -226,23 +227,19 @@ export class SyncService implements SyncServiceAbstraction {

private async needsSyncing(forceSync: boolean) {
if (forceSync) {
return [true, false];
return true;
}

const lastSync = await this.getLastSync();
if (lastSync == null || lastSync.getTime() === 0) {
return [true, false];
return true;
}

try {
const response = await this.apiService.getAccountRevisionDate();
if (new Date(response) <= lastSync) {
return [false, false];
}
return [true, false];
} catch (e) {
return [false, true];
const response = await this.apiService.getAccountRevisionDate();
if (new Date(response) <= lastSync) {
return false;
}
return true;
}

private async syncProfile(response: ProfileResponse) {
Expand Down