Class: Logfoo::Rack::Err

Inherits:
Object
  • Object
show all
Defined in:
lib/logfoo/integrations/rack/err.rb

Constant Summary collapse

TEXT_PLAIN =
'text/plain'.freeze
CLEAN_RE =
/\A(rack|puma)\./.freeze
FRAMEWORK_ERRORS =
%w{ action_dispatch.exception sinatra.error }.freeze
INTERNAL_SERVER_ERROR =
[
  500,
  {
    R::CONTENT_TYPE   => TEXT_PLAIN,
    R::CONTENT_LENGTH => Rack::Utils::HTTP_STATUS_CODES[500].bytesize
  },
  [Rack::Utils::HTTP_STATUS_CODES[500]],
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(app, log = nil) ⇒ Err



19
20
21
# File 'lib/logfoo/integrations/rack/err.rb', line 19

def initialize(app, log = nil)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/logfoo/integrations/rack/err.rb', line 23

def call(env)
  response = @app.call(env)

  if framework_error = FRAMEWORK_ERRORS.find { |k| env[k] }
    append(framework_error, env)
  end

  response
rescue Exception => e
  append(e, env)
  INTERNAL_SERVER_ERROR
end