diff --git a/lib/crane-amqp/broker.js b/lib/crane-amqp/broker.js index bfec945..d51dd94 100644 --- a/lib/crane-amqp/broker.js +++ b/lib/crane-amqp/broker.js @@ -154,17 +154,17 @@ Broker.prototype.enqueue = function(topic, msg, options, cb) { topic = topic.replace(/\//g, '.'); options.deliveryMode = (options.deliveryMode === undefined) ? PERSISTENT_MODE : options.deliveryMode; - // TODO: This option appears to have no effect. Why? + // TODO: This option appears to have no effect. Investigate why. //options.mandatory = (options.mandatory === undefined) ? true : options.mandatory; if (this._exchange.options && this._exchange.options.confirm) { debug('publish %s (confirm)', topic); - this._exchange.publish(topic, msg, options, function(hadError) { - var err; + this._exchange.publish(topic, msg, options, function(hadError, err) { if (hadError) { - err = new Error('Failed to publish message to topic "' + topic + '"'); + err = err || new Error('Failed to publish message to topic "' + topic + '"'); + return cb(err); } - return cb(err); + return cb(); }); } else { debug('publish %s', topic);