Object
This middleware rescues any exception returned by the application and calls an exceptions app that will wrap it in a format for the end user.
The exceptions app should be passed as parameter on initialization of ShowExceptions. Everytime there is an exception, ShowExceptions will store the exception in env, rewrite the PATH_INFO to the exception status code and call the rack app.
If the application returns a “X-Cascade” pass response, this middleware will send an empty response as result with the correct status code. If any exception happens inside the exceptions app, this middleware catches the exceptions and returns a FAILSAFE_RESPONSE.
# File lib/action_dispatch/middleware/show_exceptions.rb, line 39 39: def initialize(app, exceptions_app = nil) 40: if [true, false].include?(exceptions_app) 41: ActiveSupport::Deprecation.warn "Passing consider_all_requests_local option to ActionDispatch::ShowExceptions middleware no longer works" 42: exceptions_app = nil 43: end 44: 45: if exceptions_app.nil? 46: raise ArgumentError, "You need to pass an exceptions_app when initializing ActionDispatch::ShowExceptions. " "In case you want to render pages from a public path, you can use ActionDispatch::PublicExceptions.new('path/to/public')" 47: end 48: 49: @app = app 50: @exceptions_app = exceptions_app 51: end
# File lib/action_dispatch/middleware/show_exceptions.rb, line 26 26: def rescue_responses 27: ActiveSupport::Deprecation.warn "ActionDispatch::ShowExceptions.rescue_responses is deprecated. " "Please configure your exceptions using a railtie or in your application config instead." 28: ExceptionWrapper.rescue_responses 29: end
# File lib/action_dispatch/middleware/show_exceptions.rb, line 32 32: def rescue_templates 33: ActiveSupport::Deprecation.warn "ActionDispatch::ShowExceptions.rescue_templates is deprecated. " "Please configure your exceptions using a railtie or in your application config instead." 34: ExceptionWrapper.rescue_templates 35: end
# File lib/action_dispatch/middleware/show_exceptions.rb, line 54 54: def call(env) 55: begin 56: response = @app.call(env) 57: rescue Exception => exception 58: raise exception if env['action_dispatch.show_exceptions'] == false 59: end 60: 61: response || render_exception(env, exception) 62: end
# File lib/action_dispatch/middleware/show_exceptions.rb, line 83 83: def pass_response(status) 84: [status, {"Content-Type" => "text/html; charset=#{Response.default_charset}", "Content-Length" => "0"}, []] 85: end
# File lib/action_dispatch/middleware/show_exceptions.rb, line 71 71: def render_exception(env, exception) 72: wrapper = ExceptionWrapper.new(env, exception) 73: status = wrapper.status_code 74: env["action_dispatch.exception"] = wrapper.exception 75: env["PATH_INFO"] = "/#{status}" 76: response = @exceptions_app.call(env) 77: response[1]['X-Cascade'] == 'pass' ? pass_response(status) : response 78: rescue Exception => failsafe_error 79: $stderr.puts "Error during failsafe response: #{failsafe_error}\n #{failsafe_error.backtrace * "\n "}" 80: FAILSAFE_RESPONSE 81: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.