diff --git a/lib/index.js b/lib/index.js index 1a24202..74a314d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -39,23 +39,26 @@ module.exports = function loopbackComponentMq(app, settings) { RabbitMQ.log = _.get(settings, 'options.log', console) RabbitMQ.log = typeof RabbitMQ.log === 'string' ? require(RabbitMQ.log) : RabbitMQ.log + // Handle the case where unable to connect to Rabbit. rabbit.on('unreachable', () => { RabbitMQ.log.error('Unable to connect to Rabbit') - throw new Error('Unable to connect to Rabbit') + process.exit(1) }) // Graceful shutdown. process.on('SIGINT', () => { debug('Caught SIGINT - performing graceful shutdown...') rabbit.shutdown() - process.exit(0) + process.exit(1) }) // Configure the rabbit topology. rabbit.configure(settings.topology) .then(() => debug('Rabbit topology configured')) - .catch(err => RabbitMQ.log.error(err)) - + .catch(err => { + RabbitMQ.log.error('Unable to configure Rabbit topology', err.cause) + process.exit(1) + }) const connection = rabbit.configurations.default.connection const parsedConnectionUri = url.parse(connection.uri)