logging JS errors to backend logs

This commit is contained in:
azivner
2017-12-01 22:28:22 -05:00
parent 02e5d20d44
commit cba9d8b5c1
6 changed files with 59 additions and 11 deletions

View File

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