lib/boom_nats/application.rb in boom_nats-0.1.4 vs lib/boom_nats/application.rb in boom_nats-0.1.5

- old
+ new

@@ -43,17 +43,30 @@ def on_after(&block) @callbacks[:after] << block end + def error_as_json(msg, topic, error) + { + message: msg, + topic: topic, + error: "#{error.class}: #{error.message}", + backtrace: error.backtrace, + status: "error" + }.to_json + end + def start Thread.new do @callbacks[:before].each { |callback| callback.call(self) } nats_connect do |nats| @route_topics.each do |rt| @subscriptions << nats.subscribe(rt.topic, rt.options) do |msg, reply, _sub| rt.executor.new(msg, reply, nats, rt.serializer, rt.parser) + rescue StandardError => e + BoomNats.logger.error "BoomNats::error: #{e.message}" + nats.publish(reply, error_as_json(msg, rt.topic, e)) unless reply.nil? end end BoomNats.logger.debug "BoomNats::started"