Sha256: 1dd1bd16c349b21270ffc6796a39f013c204f1ea6c6e61a801bf242d4f537b53

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module ActionSubscriber
  module Middleware
    class ErrorHandler
      include ::ActionSubscriber::Logging

      def initialize(app)
        @app = app
      end

      def call(env)
        @app.call(env)
      rescue Exception => error # make sure we capture any exception from the top of the hierarchy
        logger.error { "FAILED #{env.message_id}" }

        # There is more to this rescue than meets the eye. MarchHare's java library will rescue errors
        # and attempt to close the channel with its default exception handler. To avoid this, we will
        # stop errors right here. If you want to handle errors, you must do it in the error handler and
        # it should not re-raise. As a bonus, not killing these threads is better for your runtime :).
        begin
          ::ActionSubscriber.configuration.error_handler.call(error, env.to_h)
        rescue Exception => inner_error
          logger.error { "ActionSubscriber error handler raised error, but should never raise. Error: #{inner_error}" }
        end
      ensure
        env.safe_nack # Make sure we attempt to `nack` a message that did not get processed if something fails
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
action_subscriber-5.1.0-java lib/action_subscriber/middleware/error_handler.rb
action_subscriber-5.1.0 lib/action_subscriber/middleware/error_handler.rb
action_subscriber-5.1.0.pre-java lib/action_subscriber/middleware/error_handler.rb
action_subscriber-5.1.0.pre lib/action_subscriber/middleware/error_handler.rb