lib/dispatch-rider/dispatcher.rb in dispatch-rider-0.0.3 vs lib/dispatch-rider/dispatcher.rb in dispatch-rider-0.0.4

- old
+ new

@@ -10,12 +10,25 @@ def_delegators :handler_registrar, :register, :fetch, :unregister def initialize @handler_registrar = Registrars::Handler.new + @error_handler = method(:default_error_handler) end + def on_error(&block) + @error_handler = block + end + def dispatch(message) handler_registrar.fetch(message.subject).process(message.body) + rescue Exception => exception + @error_handler.call(message, exception) + end + + private + + def default_error_handler(message, exception) + raise exception end end end