Class: RescueRegistry::ExceptionsApp
- Inherits:
-
Object
- Object
- RescueRegistry::ExceptionsApp
- Defined in:
- lib/rescue_registry/exceptions_app.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ExceptionsApp
constructor
A new instance of ExceptionsApp.
Constructor Details
#initialize(app) ⇒ ExceptionsApp
Returns a new instance of ExceptionsApp.
3 4 5 |
# File 'lib/rescue_registry/exceptions_app.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rescue_registry/exceptions_app.rb', line 7 def call(env) request = ::ActionDispatch::Request.new(env) exception = request.get_header "action_dispatch.exception" if RescueRegistry.handles_exception?(exception) content_type = request.formats.first || Mime[:text] response = RescueRegistry.response_for_public(content_type, exception) end if response status, body, format = response if request.path_info != "/#{status}" warn "status mismatch; path_info=#{request.path_info}; status=#{status}" end [status, { "Content-Type" => "#{format}; charset=#{::ActionDispatch::Response.default_charset}", "Content-Length" => body.bytesize.to_s }, [body]] else # If we have no response, it means one of the following: # * RescueRegistry doesn't handle this exception # * RescueRegistry doesn't have a response to render for this content_type. # In either case, we use the default handler instead @app.call(env) end end |