fix: catch errors in ws on handlers
This commit is contained in:
parent
19a9d63d6c
commit
b8d3dbfa39
1 changed files with 12 additions and 0 deletions
12
index.js
12
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue