sc-manager/api/util.mjs

16 lines
502 B
JavaScript
Raw Normal View History

2020-09-08 07:53:42 +00:00
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)
}
}
}