Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions view/base/web/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,43 @@
sendTimer = window.setTimeout(sendError, sendDelay);
};



// Override console.error method so these errors are also logged

var originalConsole = {
error: console.error
};


function logToQueue(type, args) {
if (sendQueue.length > 100) {
// That's a lot of errors! Let's not overwhelm the server with more.
return;
}
if (!sendQueue.length) {
sendTimer = window.setTimeout(sendError, sendDelay);
}
Comment on lines +39 to +45
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we perhaps move this into a shared function instead of duplicating this logic?

Maybe we can pass in { colno: event.colno, filename: event.filename, lineno: event.lineno, message: event.message, stack: event.error && event.error.stack } in the original and { message: Array.from(args).join(' ') } (or whatever is appropriate here) in this new feature, and then the shared function can add the timer key and send this as the event object to the sendQueue.push() call?

sendQueue.push({
browser: {
height: window.innerHeight,
url: window.location.href,
width: window.innerWidth,
},
Comment on lines +47 to +51
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block (and event.timer) below could be part of the shared-functionality function.

event: {
type: type,
Copy link
Owner

@fredden fredden Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a column that this (type) maps to in the PHP/database side? I don't see this key in the original object below.

message: Array.from(args).join(' '),
timer: (performance.now() / 1000).toFixed(2),
},
});
}

console.error = function() {
logToQueue('error', arguments);
originalConsole.error.apply(console, arguments);
};


window.addEventListener('error', function (event) {
if (!event) {
return;
Expand Down