Class: NdrError::Recorder

Inherits:
Object
  • Object
show all
Defined in:
lib/ndr_error/recorder.rb

Overview

Middleware for logging exceptions, can be used as exception_app for Rails.

Direct Known Subclasses

Middleware::PublicExceptions

Instance Method Summary collapse

Constructor Details

#initialize(parent_handler) ⇒ Recorder

the parent_handler could be the host app’s routes, or an instance of ActionDispatch::PublicExceptions, or any other middleware.



6
7
8
# File 'lib/ndr_error/recorder.rb', line 6

def initialize(parent_handler)
  @parent_handler = parent_handler
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ndr_error/recorder.rb', line 10

def call(env)
  rescuing_everything do
    request   = ActionDispatch::Request.new(env)
    exception = env['action_dispatch.exception']

    # "falsey" callback return value allows logging to be skipped
    log_exception(request, exception) if run_exception_callback(request, exception)
  end

  @parent_handler.call(env)
end