mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 10:40:41 +01:00
error handling in custom request handler
This commit is contained in:
@@ -173,6 +173,23 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
*/
|
||||
this.createNote = noteService.createNote;
|
||||
|
||||
/**
|
||||
* Creates new note according to given params and force all connected clients to refresh their tree.
|
||||
*
|
||||
* @method
|
||||
*
|
||||
* @param {string} parentNoteId - create new note under this parent
|
||||
* @param {string} title
|
||||
* @param {string} [content=""]
|
||||
* @param {CreateNoteExtraOptions} [extraOptions={}]
|
||||
* @returns {Promise<{note: Note, branch: Branch}>} object contains newly created entities note and branch
|
||||
*/
|
||||
this.createNoteAndRefresh = async function(parentNoteId, title, content, extraOptions) {
|
||||
await noteService.createNote(parentNoteId, title, content, extraOptions);
|
||||
|
||||
messagingService.refreshTree();
|
||||
};
|
||||
|
||||
/**
|
||||
* Log given message to trilium logs.
|
||||
*
|
||||
@@ -238,7 +255,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
*
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
this.refreshTree = () => messagingService.sendMessageToAllClients({ type: 'refresh-tree' });
|
||||
this.refreshTree = messagingService.refreshTree;
|
||||
|
||||
/**
|
||||
* @return {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version
|
||||
|
||||
@@ -432,7 +432,7 @@ async function runChecks() {
|
||||
});
|
||||
|
||||
if (fixedIssues) {
|
||||
messagingService.sendMessageToAllClients({ type: 'refresh-tree' });
|
||||
messagingService.refreshTree();
|
||||
}
|
||||
|
||||
if (unrecoverableConsistencyErrors) {
|
||||
|
||||
@@ -12,7 +12,7 @@ async function runAttachedRelations(note, relationName, originEntity) {
|
||||
const scriptNote = await relation.getTargetNote();
|
||||
|
||||
if (scriptNote) {
|
||||
await scriptService.executeNote(scriptNote, { originEntity });
|
||||
await scriptService.executeNoteNoException(scriptNote, { originEntity });
|
||||
}
|
||||
else {
|
||||
log.error(`Target note ${relation.value} of atttribute ${relation.attributeId} has not been found.`);
|
||||
@@ -30,7 +30,7 @@ eventService.subscribe(eventService.NOTE_TITLE_CHANGED, async note => {
|
||||
if (await parent.hasLabel("sorted")) {
|
||||
await treeService.sortNotesAlphabetically(parent.noteId);
|
||||
|
||||
messagingService.sendMessageToAllClients({ type: 'refresh-tree' });
|
||||
messagingService.refreshTree();
|
||||
break; // sending the message once is enough
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ async function sendMessage(client, message) {
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshTree() {
|
||||
await sendMessageToAllClients({ type: 'refresh-tree' });
|
||||
}
|
||||
|
||||
async function sendMessageToAllClients(message) {
|
||||
const jsonStr = JSON.stringify(message);
|
||||
|
||||
@@ -76,5 +80,6 @@ async function sendPing(client, lastSentSyncId) {
|
||||
|
||||
module.exports = {
|
||||
init,
|
||||
refreshTree,
|
||||
sendMessageToAllClients
|
||||
};
|
||||
@@ -17,7 +17,7 @@ async function runNotesWithLabel(runAttrValue) {
|
||||
AND notes.isDeleted = 0`, [runAttrValue]);
|
||||
|
||||
for (const note of notes) {
|
||||
scriptService.executeNote(note, { originEntity: note });
|
||||
scriptService.executeNoteNoException(note, { originEntity: note });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,15 @@ async function executeNote(note, apiParams) {
|
||||
await executeBundle(bundle, apiParams);
|
||||
}
|
||||
|
||||
async function executeNoteNoException(note, apiParams) {
|
||||
try {
|
||||
await executeNote(note, apiParams);
|
||||
}
|
||||
catch (e) {
|
||||
// just swallow, exception is logged already in executeNote
|
||||
}
|
||||
}
|
||||
|
||||
async function executeBundle(bundle, apiParams = {}) {
|
||||
if (!apiParams.startNote) {
|
||||
// this is the default case, the only exception is when we want to preserve frontend startNote
|
||||
@@ -36,6 +45,8 @@ async function executeBundle(bundle, apiParams = {}) {
|
||||
}
|
||||
catch (e) {
|
||||
log.error(`Execution of script "${bundle.note.title}" (${bundle.note.noteId}) failed with error: ${e.message}`);
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +179,7 @@ function sanitizeVariableName(str) {
|
||||
|
||||
module.exports = {
|
||||
executeNote,
|
||||
executeNoteNoException,
|
||||
executeScript,
|
||||
getScriptBundleForFrontend
|
||||
};
|
||||
Reference in New Issue
Block a user