Comparing version 1.0.5 to 1.0.6
59
index.js
@@ -37,2 +37,4 @@ 'use strict' | ||
Remit.prototype.on_error = null | ||
Remit.prototype.res = function res (event, callback, context, options) { | ||
@@ -70,10 +72,26 @@ debug('res') | ||
if (!info.correlationId || !info.replyTo) { | ||
return callback(context, msg, null, event_info) | ||
try { | ||
callback(context, msg, null, event_info) | ||
} catch (e) { | ||
if (self.on_error) { | ||
self.on_error(e) | ||
} else { | ||
throw new Error(e) | ||
} | ||
} | ||
} else { | ||
try { | ||
callback.call(context, msg, function (err, data) { | ||
let options = {correlationId: info.correlationId} | ||
self._exchange.publish(info.replyTo, Array.prototype.slice.call(arguments), options) | ||
}) | ||
} catch (e) { | ||
if (self.on_error) { | ||
self.on_error(e) | ||
} else { | ||
throw new Error(e) | ||
} | ||
} | ||
} | ||
return callback.call(context, msg, function (err, data) { | ||
let options = {correlationId: info.correlationId} | ||
self._exchange.publish(info.replyTo, Array.prototype.slice.call(arguments), options) | ||
}) | ||
}) | ||
@@ -129,11 +147,16 @@ | ||
callback({ | ||
event, | ||
args, | ||
options, | ||
message: 'Timed out after no response for ' + (options.timeout || 5000) + 'ms' | ||
}) | ||
debug(self._results_callback) | ||
debug(self._results_timeouts) | ||
try { | ||
callback({ | ||
event, | ||
args, | ||
options, | ||
message: 'Timed out after no response for ' + (options.timeout || 5000) + 'ms' | ||
}) | ||
} catch (e) { | ||
if (self.on_error) { | ||
self.on_error(e) | ||
} else { | ||
throw new Error(e) | ||
} | ||
} | ||
} | ||
@@ -225,5 +248,3 @@ }, options.timeout || 5000) | ||
this._connection.on('error', function (err) { | ||
debug(err) | ||
process.exit(1) | ||
throw new Error(err) | ||
}) | ||
@@ -230,0 +251,0 @@ } |
{ | ||
"name": "remit", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "`remit` is intended to be a small set of functionality used to create simple microservices that don't need to be aware of one-another's existence.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
16374
265