improved error handling

This commit is contained in:
zadam
2023-09-21 11:16:03 +02:00
parent 5dd6f49104
commit bb81f110dd
6 changed files with 62 additions and 55 deletions
+4
View File
@@ -895,6 +895,10 @@ async function asyncPostProcessContent(note, content) {
// all keys should be replaced by the corresponding values
function replaceByMap(str, mapObj) {
if (!mapObj) {
return str;
}
const re = new RegExp(Object.keys(mapObj).join("|"),"g");
return str.replace(re, matched => mapObj[matched]);
+1 -1
View File
@@ -93,7 +93,7 @@ async function setupSyncFromSyncServer(syncServerHost, syncProxy, password) {
return { result: 'success' };
}
catch (e) {
log.error(`Sync failed: ${e.message}`);
log.error(`Sync failed: '${e.message}', stack: ${e.stack}`);
return {
result: 'failure',
+1 -2
View File
@@ -71,8 +71,7 @@ async function sync() {
};
}
else {
log.info(`sync failed: ${e.message}
stack: ${e.stack}`);
log.info(`Sync failed: '${e.message}', stack: ${e.stack}`);
ws.syncFailed();
+8 -4
View File
@@ -46,6 +46,10 @@ function updateNormalEntity(remoteEC, remoteEntityRow, instanceId) {
}
if (!localEC || localEC.utcDateChanged <= remoteEC.utcDateChanged) {
if (!remoteEntityRow) {
throw new Error(`Empty entity row for: ${JSON.stringify(remoteEC)}`);
}
if (remoteEC.entityName === 'blobs' && remoteEntityRow.content !== null) {
// we always use a Buffer object which is different from normal saving - there we use a simple string type for
// "string notes". The problem is that in general, it's not possible to detect whether a blob content
@@ -59,10 +63,6 @@ function updateNormalEntity(remoteEC, remoteEntityRow, instanceId) {
}
}
if (!remoteEntityRow) {
throw new Error(`Empty entity row for: ${JSON.stringify(remoteEC)}`);
}
sql.replace(remoteEC.entityName, remoteEntityRow);
if (!localEC || localEC.utcDateChanged < remoteEC.utcDateChanged) {
@@ -81,6 +81,10 @@ function updateNormalEntity(remoteEC, remoteEntityRow, instanceId) {
}
function updateNoteReordering(remoteEC, remoteEntityRow, instanceId) {
if (!remoteEntityRow) {
throw new Error(`Empty note_reordering body for: ${JSON.stringify(remoteEC)}`);
}
for (const key in remoteEntityRow) {
sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?", [remoteEntityRow[key], key]);
}