diff --git a/index.js b/index.js index 9ad7b85..8758647 100644 --- a/index.js +++ b/index.js @@ -151,6 +151,18 @@ function bootstrapWebsocketHandler(route) { // initialize ws router. future updates will only require updating // the wsRoutes dict, not create a whole new route wsRouter.ws(routeWithPrefix(route), (ws, req) => { + const myOn = ws.on.bind(ws) + ws.on = (thing, cb) => { + myOn(thing, (...args) => { + try { + cb(...args) + } + catch (e) { + const error = e.stack ? `${e}\n\n${e.stack}` : `${e}`; + model.createLog(db, route.structure_id, route.id, error, true); + } + }) + } ws.render = (template, context) => { context = context || {}; context.route = function (url) {