UNPKG

diffusion

Version:

Diffusion JavaScript client

21 lines (19 loc) 658 B
var ErrorReason = require('../../errors/error-reason'); /** * Factory for command services, wrapping the service implementation to catch errors and dispatch an appropriate * error response to the request callback. * * @param {Function} service the command service handler function * @returns {Object} command service wrapper */ module.exports.create = function(service) { return { onRequest : function(internal, message, callback) { try { service(internal, message, callback); } catch (e) { callback.fail(ErrorReason.CALLBACK_EXCEPTION, e.message); } } }; };