fix: catch errors in ws on handlers

This commit is contained in:
Your Name 2025-02-01 00:10:55 -05:00
parent 19a9d63d6c
commit b8d3dbfa39

View file

@ -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) {