class Logfoo::Rack::Err

Constants

CLEAN_RE
FRAMEWORK_ERRORS
INTERNAL_SERVER_ERROR
TEXT_PLAIN

Public Class Methods

new(app, log = nil) click to toggle source
# File lib/logfoo/integrations/rack/err.rb, line 17
def initialize(app, log = nil)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/logfoo/integrations/rack/err.rb, line 21
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

Private Instance Methods

append(e, env) click to toggle source
# File lib/logfoo/integrations/rack/err.rb, line 36
def append(e, env)
  env   = clean_env(env)
  env   = prefix_env(env)
  line  = Logfoo::ErrLine.build(
    logger_name: LOGGER_NAME,
    exception:   e,
    payload:     env
  )
  Logfoo::App.instance.append(line)
end
clean_env(env) click to toggle source
# File lib/logfoo/integrations/rack/err.rb, line 54
def clean_env(env)
  env.inject({}) do |ac, (key, value) |
    case
    when key =~ CLEAN_RE
      ac
    else
      ac.merge!(key => value)
    end
  end
end
prefix_env(env) click to toggle source
# File lib/logfoo/integrations/rack/err.rb, line 47
def prefix_env(env)
  env.inject({}) do |ac, (key, value)|
    ac.merge!("env.#{key}" => value)
    ac
  end
end