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.
Methods
- C
- N
- R
Constants
FAILSAFE_RESPONSE | = | [500, {'Content-Type' => 'text/html'}, ["<html><body><h1>500 Internal Server Error</h1>" << "If you are the administrator of this website, then please read this web " << "application's log file and/or the web server's log file to find out what " << "went wrong.</body></html>"]] |
Class Public methods
# File actionpack/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. " \ 47: "In case you want to render pages from a public path, you can use ActionDispatch::PublicExceptions.new('path/to/public')" 48: end 49: 50: @app = app 51: @exceptions_app = exceptions_app 52: end
# File actionpack/lib/action_dispatch/middleware/show_exceptions.rb, line 26 26: def rescue_responses 27: ActiveSupport::Deprecation.warn "ActionDispatch::ShowExceptions.rescue_responses is deprecated. " \ 28: "Please configure your exceptions using a railtie or in your application config instead." 29: ExceptionWrapper.rescue_responses 30: end
# File actionpack/lib/action_dispatch/middleware/show_exceptions.rb, line 32 32: def rescue_templates 33: ActiveSupport::Deprecation.warn "ActionDispatch::ShowExceptions.rescue_templates is deprecated. " \ 34: "Please configure your exceptions using a railtie or in your application config instead." 35: ExceptionWrapper.rescue_templates 36: end
Instance Public methods
# File actionpack/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