Class: Vx::Lib::Logger::Rack::HandleExceptions

Inherits:
Struct
  • Object
show all
Defined in:
lib/vx/lib/logger/rack/handle_exceptions.rb

Constant Summary collapse

IGNORED_EXCEPTIONS =
%w{
  ActionController::RoutingError
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject

Returns the value of attribute app

Returns:

  • (Object)

    the current value of app



4
5
6
# File 'lib/vx/lib/logger/rack/handle_exceptions.rb', line 4

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vx/lib/logger/rack/handle_exceptions.rb', line 26

def call(env)
  begin
    response = app.call(env)
  rescue Exception => ex
    notify ex, env
  end

  if ex = framework_exception(env)
    notify ex, env
  end

  response
end

#clean_env(env) ⇒ Object



10
11
12
13
14
15
# File 'lib/vx/lib/logger/rack/handle_exceptions.rb', line 10

def clean_env(env)
  env = env.select do |k,v|
    k !~ /^(action_dispatch|puma|session|rack\.session|action_controller|HTTP_COOKIE|ROUTES_[0-9]+_SCRIPT_NAME)/
  end
  env
end

#framework_exception(env) ⇒ Object



40
41
42
# File 'lib/vx/lib/logger/rack/handle_exceptions.rb', line 40

def framework_exception(env)
  env['rack.exception'] || env['action_dispatch.exception']
end

#ignore?(ex) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/vx/lib/logger/rack/handle_exceptions.rb', line 44

def ignore?(ex)
  IGNORED_EXCEPTIONS.include? ex.class.name
end

#notify(exception, env) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/vx/lib/logger/rack/handle_exceptions.rb', line 17

def notify(exception, env)
  unless ignore?(exception)
    Lib::Logger.get.fatal(
      "Unhandled exception: #{exception.class} - #{exception.message}",
      clean_env(env).merge(exception: exception)
    )
  end
end