Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
better reporting of sync error when "sync now"
azivner68c2edea45cd
diff --git a/public/javascripts/sync.js b/public/javascripts/sync.jsindex 50729c703a..b3c84aa2fd 100644--- a/public/javascripts/sync.js+++ b/public/javascripts/sync.js@@ -8,12 +8,16 @@ function syncNow() {if (result.success) {status.checkStatus();- message("Sync triggered.");+ message("Sync finished successfully.");}else {- error("Sync failed");+ if (result.message.length > 50) {+ result.message = result.message.substr(0, 50);+ }++ error("Sync failed: " + result.message);}},- error: () => error("Sync failed")+ error: () => error("Sync failed for unknown reason.")});}\ No newline at end of filediff --git a/routes/api/sync.js b/routes/api/sync.jsindex ee2306bbaa..2d3b3b9e78 100644--- a/routes/api/sync.js+++ b/routes/api/sync.js@@ -8,11 +8,7 @@ const sql = require('../../services/sql');const options = require('../../services/options');router.post('/now', auth.checkApiAuth, async (req, res, next) => {- await sync.sync();-- res.send({- success: true- });+ res.send(await sync.sync());});router.get('/changed', auth.checkApiAuth, async (req, res, next) => {diff --git a/services/sync.js b/services/sync.jsindex 496e6b4d5e..142d12cb21 100644--- a/services/sync.js+++ b/services/sync.js@@ -195,7 +195,10 @@ async function sync() {if (syncInProgress) {logSyncError("Sync already in progress");- return;+ return {+ success: false,+ message: "Sync already in progress"+ };}syncInProgress = true;@@ -204,7 +207,10 @@ async function sync() {if (!await migration.isDbUpToDate()) {logSyncError("DB not up to date");- return;+ return {+ success: false,+ message: "DB not up to date"+ };}const syncContext = await login();@@ -214,9 +220,18 @@ async function sync() {await pullSync(syncContext);await pushSync(syncContext);++ return {+ success: true+ };}catch (e) {logSync("sync failed: " + e.stack);++ return {+ success: false,+ message: e.message+ }}finally {syncInProgress = false;