mirror of
https://github.com/zadam/trilium.git
synced 2024-12-24 08:13:53 +08:00
better reporting of sync error when "sync now"
This commit is contained in:
parent
b64ef6311c
commit
68c2edea45
3 changed files with 25 additions and 10 deletions
|
@ -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.")
|
||||
});
|
||||
}
|
|
@ -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) => {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue