service-core/dev/api/util.mjs
2020-09-07 00:47:53 +00:00

16 lines
No EOL
502 B
JavaScript

export function safeWrap(log, name, fn) {
return function(data, cb) {
try {
let out = fn(data, cb)
if (out && out.then) {
out.then(function() {}, function(err) {
log.error(err, 'Unknown error in ' + name)
log.event.error('Unknown error occured in ' + name + ': ' + err.message)
})
}
} catch (err) {
log.error(err, 'Unknown error in ' + name)
log.event.error('Unknown error occured in ' + name + ': ' + err.message)
}
}
}