Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: do not throw on sync already running

thecodrre0202cd22ad5
diff --git a/packages/core/api/sync/index.js b/packages/core/api/sync/index.js
index 478b283ba..3f9c6eb54 100644
--- a/packages/core/api/sync/index.js
+++ b/packages/core/api/sync/index.js
@@ -53,10 +53,8 @@ export default class Sync {
}
async _performChecks() {
- if (this._isSyncing) throw new Error("Sync already running.");
let lastSynced = (await this._db.context.read("lastSynced")) || 0;
let token = await this._tokenManager.getAccessToken();
- if (!token) throw new Error("You need to login to sync.");
// update the conflicts status and if find any, throw
await this._db.conflicts.recalculate();
@@ -66,6 +64,8 @@ export default class Sync {
}
async start(full, force) {
+ if (this._isSyncing) return false;
+
if (force) await this._db.context.write("lastSynced", 0);
let { lastSynced, token } = await this._performChecks();
@@ -94,6 +94,8 @@ export default class Sync {
if (lastSynced) {
await this._db.context.write("lastSynced", lastSynced);
}
+
+ return true;
} catch (e) {
throw e;
} finally {
diff --git a/packages/core/api/token-manager.js b/packages/core/api/token-manager.js
index f81154de1..fee82ba69 100644
--- a/packages/core/api/token-manager.js
+++ b/packages/core/api/token-manager.js
@@ -45,7 +45,7 @@ class TokenManager {
if (e.message === "invalid_grant" || e.message === "invalid_client") {
EV.publish(EVENTS.userSessionExpired);
}
- return null;
+ throw e;
}
}