From b8d3dbfa399239bb6e93f4018a9d33b0abcc5246 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 1 Feb 2025 00:10:55 -0500 Subject: [PATCH] fix: catch errors in ws on handlers --- index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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) {