error handling in custom request handler

This commit is contained in:
zadam
2019-02-03 11:15:32 +01:00
parent d3ca6b5ae6
commit bad7b84993
10 changed files with 59 additions and 14 deletions

View File

@@ -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
};