Commit b533d239 authored by yann300's avatar yann300

wrap call with try catch

parent c950c2af
...@@ -19,16 +19,29 @@ class Router { ...@@ -19,16 +19,29 @@ class Router {
} }
call (callid, name, fn, args) { call (callid, name, fn, args) {
servicesList[name][fn](args, (error, data) => { try {
var response = { servicesList[name][fn](args, (error, data) => {
id: callid, var response = {
type: 'reply', id: callid,
scope: name, type: 'reply',
result: data, scope: name,
error: error result: data,
error: error
}
this.websocket.send(JSON.stringify(response))
})
} catch (e) {
var msg = 'Unexpected Error ' + e.message
console.log('\x1b[31m%s\x1b[0m', '[ERR] ' + msg)
if (this.websocket) {
this.websocket.send(JSON.stringify({
id: callid,
type: 'reply',
scope: name,
error: msg
}))
} }
this.websocket.send(JSON.stringify(response)) }
})
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment