Class: Vx::Lib::Instrumentation::Rack::HandleExceptionsMiddleware
- Inherits:
-
Struct
- Object
- Struct
- Vx::Lib::Instrumentation::Rack::HandleExceptionsMiddleware
- Defined in:
- lib/vx/lib/instrumentation/rack/handle_exceptions_middleware.rb
Constant Summary collapse
- IGNORED_EXCEPTIONS =
%w{ ActionController::RoutingError }
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #clean_env(env) ⇒ Object
- #framework_exception(env) ⇒ Object
- #ignore?(ex) ⇒ Boolean
- #notify(exception, env) ⇒ Object
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app
4 5 6 |
# File 'lib/vx/lib/instrumentation/rack/handle_exceptions_middleware.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 39 |
# File 'lib/vx/lib/instrumentation/rack/handle_exceptions_middleware.rb', line 26 def call(env) begin response = app.call(env) rescue Exception => ex notify ex, env raise ex end if ex = framework_exception(env) notify ex, env end response end |
#clean_env(env) ⇒ Object
10 11 12 13 14 |
# File 'lib/vx/lib/instrumentation/rack/handle_exceptions_middleware.rb', line 10 def clean_env(env) env = env.select{|k,v| k !~ /^(action_dispatch|puma|session|rack\.session|action_controller)/ } env['HTTP_COOKIE'] &&= env['HTTP_COOKIE'].scan(/.{80}/).join("\n") env end |
#framework_exception(env) ⇒ Object
41 42 43 |
# File 'lib/vx/lib/instrumentation/rack/handle_exceptions_middleware.rb', line 41 def framework_exception(env) env['rack.exception'] || env['action_dispatch.exception'] end |
#ignore?(ex) ⇒ Boolean
45 46 47 |
# File 'lib/vx/lib/instrumentation/rack/handle_exceptions_middleware.rb', line 45 def ignore?(ex) IGNORED_EXCEPTIONS.include? ex.class.name end |
#notify(exception, env) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/vx/lib/instrumentation/rack/handle_exceptions_middleware.rb', line 16 def notify(exception, env) unless ignore?(exception) Lib::Instrumentation.handle_exception( 'handle_exception.rack', exception, clean_env(env) ) end end |