class ExceptionHunter::Middleware::RequestHunter

{www.rubyguides.com/2018/09/rack-middleware Rack Middleware} used to rescue from exceptions track them and then re-raise them.

Constants

ENVIRONMENT_KEYS
FILTERED_PARAMS

Public Class Methods

new(app) click to toggle source
# File lib/exception_hunter/middleware/request_hunter.rb, line 19
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/exception_hunter/middleware/request_hunter.rb, line 23
def call(env)
  @app.call(env)
rescue Exception => exception # rubocop:disable Lint/RescueException
  catch_prey(env, exception)
  raise exception
end

Private Instance Methods

catch_prey(env, exception) click to toggle source
# File lib/exception_hunter/middleware/request_hunter.rb, line 32
def catch_prey(env, exception)
  user = user_from_env(env)
  ErrorCreator.call(
    tag: ErrorCreator::HTTP_TAG,
    class_name: exception.class.to_s,
    message: exception.message,
    environment_data: environment_data(env),
    backtrace: exception.backtrace,
    user: user
  )
end
environment_data(env) click to toggle source
# File lib/exception_hunter/middleware/request_hunter.rb, line 44
def environment_data(env)
  env
    .select { |key, _value| ENVIRONMENT_KEYS.include?(key) }
    .merge(params: filtered_sensitive_params(env))
end
filtered_sensitive_params(env) click to toggle source
# File lib/exception_hunter/middleware/request_hunter.rb, line 56
def filtered_sensitive_params(env)
  params = env['action_dispatch.request.parameters']
  ExceptionHunter::DataRedacter.new(params, FILTERED_PARAMS).redact
end
user_from_env(env) click to toggle source
# File lib/exception_hunter/middleware/request_hunter.rb, line 50
def user_from_env(env)
  current_user_method = Config.current_user_method
  controller = env['action_controller.instance']
  controller.try(current_user_method)
end