mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
logging JS errors to backend logs
This commit is contained in:
parent
02e5d20d44
commit
cba9d8b5c1
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,20 @@ function init(httpServer, sessionParser) {
|
||||
server: httpServer
|
||||
});
|
||||
|
||||
webSocketServer.on('connection', function connection(ws, req) {
|
||||
webSocketServer.on('connection', (ws, req) => {
|
||||
console.log("websocket client connected");
|
||||
|
||||
ws.on('message', messageJson => {
|
||||
const message = JSON.parse(messageJson);
|
||||
|
||||
if (message.type === 'log-error') {
|
||||
log.error('JS Error: ' + message.error);
|
||||
}
|
||||
else {
|
||||
log.error('Unrecognized message: ');
|
||||
log.error(message);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user