wrap call with try catch

pull/3094/head
yann300 7 years ago
parent a5121a69de
commit 7efd5dc0a7
  1. 31
      src/router.js

@ -19,16 +19,29 @@ class Router {
}
call (callid, name, fn, args) {
servicesList[name][fn](args, (error, data) => {
var response = {
id: callid,
type: 'reply',
scope: name,
result: data,
error: error
try {
servicesList[name][fn](args, (error, data) => {
var response = {
id: callid,
type: 'reply',
scope: name,
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))
})
}
}
}

Loading…
Cancel
Save