mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-01-06 04:50:03 -06:00
logging JS errors to backend logs
This commit is contained in:
@@ -121,7 +121,7 @@ const contextMenu = (function() {
|
||||
treeChanges.deleteNode(node);
|
||||
}
|
||||
else {
|
||||
console.log("Unknown command: " + ui.cmd);
|
||||
messaging.logError("Unknown command: " + ui.cmd);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -80,7 +80,7 @@ const jumpToNote = (function() {
|
||||
dialogEl.dialog("close");
|
||||
}
|
||||
else {
|
||||
console.error("Unknown action=" + action);
|
||||
messaging.logError("Unknown action=" + action);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -125,4 +125,27 @@ function showAppIfHidden() {
|
||||
// Kick off the CSS transition
|
||||
loaderDiv.style.opacity = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
||||
const string = msg.toLowerCase();
|
||||
|
||||
let message = "Uncaught error: ";
|
||||
|
||||
if (string.indexOf("script error") > -1){
|
||||
message += 'No details available';
|
||||
}
|
||||
else {
|
||||
message += [
|
||||
'Message: ' + msg,
|
||||
'URL: ' + url,
|
||||
'Line: ' + lineNo,
|
||||
'Column: ' + columnNo,
|
||||
'Error object: ' + JSON.stringify(error)
|
||||
].join(' - ');
|
||||
}
|
||||
|
||||
messaging.logError(message);
|
||||
|
||||
return false;
|
||||
};
|
||||
@@ -1,9 +1,20 @@
|
||||
"use strict";
|
||||
|
||||
const messaging = (function() {
|
||||
function messageHandler(event) {
|
||||
console.log(event.data);
|
||||
let ws = null;
|
||||
|
||||
function logError(message) {
|
||||
console.error(message);
|
||||
|
||||
if (ws && ws.readyState === 1) {
|
||||
ws.send(JSON.stringify({
|
||||
type: 'log-error',
|
||||
error: message
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
function messageHandler(event) {
|
||||
const message = JSON.parse(event.data);
|
||||
|
||||
if (message.type === 'sync') {
|
||||
@@ -27,8 +38,6 @@ const messaging = (function() {
|
||||
}
|
||||
}
|
||||
|
||||
let ws = null;
|
||||
|
||||
function connectWebSocket() {
|
||||
// use wss for secure messaging
|
||||
ws = new WebSocket("ws://" + location.host);
|
||||
@@ -65,4 +74,8 @@ const messaging = (function() {
|
||||
showMessage("Re-connected to server");
|
||||
}
|
||||
}, 3000);
|
||||
|
||||
return {
|
||||
logError
|
||||
};
|
||||
})();
|
||||
@@ -144,7 +144,7 @@ const noteTree = (function() {
|
||||
function prepareNoteTreeInner(parentNoteId) {
|
||||
const childNoteIds = parentToChildren[parentNoteId];
|
||||
if (!childNoteIds) {
|
||||
console.log("No children for " + parentNoteId + ". This shouldn't happen.");
|
||||
messaging.logError("No children for " + parentNoteId + ". This shouldn't happen.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ const noteTree = (function() {
|
||||
const parents = childToParents[childNoteId];
|
||||
|
||||
if (!parents) {
|
||||
console.error("No parents found for " + childNoteId);
|
||||
messaging.logError("No parents found for " + childNoteId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ const noteTree = (function() {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
console.log("No parents, can't activate node.");
|
||||
messaging.logError("No parents, can't activate node.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user