aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-05-02 23:02:22 -0500
committerJoshua Peek <josh@joshpeek.com>2009-05-02 23:02:22 -0500
commit11af089cee0a0e744e267d32becfe2c66a586d31 (patch)
tree970e6172381f5f246ffbb48b3b46c5393d56a7ec /actionpack/lib
parent1c6fcbfd2d67ce2b2faa29d956566b48e9a61188 (diff)
downloadrails-11af089cee0a0e744e267d32becfe2c66a586d31.tar.gz
rails-11af089cee0a0e744e267d32becfe2c66a586d31.tar.bz2
rails-11af089cee0a0e744e267d32becfe2c66a586d31.zip
Extract ActionController rescue templates into Rescue and ShowExceptions middleware.
This commit breaks all exception catching plugins like ExceptionNotifier. These plugins should be rewritten as middleware instead overriding Controller#rescue_action_in_public.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller.rb2
-rw-r--r--actionpack/lib/action_controller/base/base.rb9
-rw-r--r--actionpack/lib/action_controller/base/rescue.rb50
-rw-r--r--actionpack/lib/action_controller/dispatch/dispatcher.rb16
-rw-r--r--actionpack/lib/action_controller/dispatch/middlewares.rb5
-rw-r--r--actionpack/lib/action_controller/dispatch/rescue.rb185
-rw-r--r--actionpack/lib/action_controller/dispatch/templates/rescues/diagnostics.erb10
-rw-r--r--actionpack/lib/action_dispatch.rb2
-rw-r--r--actionpack/lib/action_dispatch/middleware/rescue.rb14
-rw-r--r--actionpack/lib/action_dispatch/middleware/show_exceptions.rb142
-rw-r--r--actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (renamed from actionpack/lib/action_controller/dispatch/templates/rescues/_request_and_response.erb)6
-rw-r--r--actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb (renamed from actionpack/lib/action_controller/dispatch/templates/rescues/_trace.erb)0
-rw-r--r--actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb10
-rw-r--r--actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb (renamed from actionpack/lib/action_controller/dispatch/templates/rescues/layout.erb)4
-rw-r--r--actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.erb (renamed from actionpack/lib/action_controller/dispatch/templates/rescues/missing_template.erb)0
-rw-r--r--actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb (renamed from actionpack/lib/action_controller/dispatch/templates/rescues/routing_error.erb)0
-rw-r--r--actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb (renamed from actionpack/lib/action_controller/dispatch/templates/rescues/template_error.erb)6
-rw-r--r--actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb (renamed from actionpack/lib/action_controller/dispatch/templates/rescues/unknown_action.erb)0
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/response.rb8
19 files changed, 239 insertions, 230 deletions
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb
index aee6b9dc9f..ab78bc9222 100644
--- a/actionpack/lib/action_controller.rb
+++ b/actionpack/lib/action_controller.rb
@@ -60,7 +60,7 @@ module ActionController
autoload :Redirector, 'action_controller/base/redirect'
autoload :Renderer, 'action_controller/base/render'
autoload :RequestForgeryProtection, 'action_controller/base/request_forgery_protection'
- autoload :Rescue, 'action_controller/dispatch/rescue'
+ autoload :Rescue, 'action_controller/base/rescue'
autoload :Resources, 'action_controller/routing/resources'
autoload :Responder, 'action_controller/base/responder'
autoload :Routing, 'action_controller/routing'
diff --git a/actionpack/lib/action_controller/base/base.rb b/actionpack/lib/action_controller/base/base.rb
index 60567454b1..7bbde519cc 100644
--- a/actionpack/lib/action_controller/base/base.rb
+++ b/actionpack/lib/action_controller/base/base.rb
@@ -30,10 +30,6 @@ module ActionController #:nodoc:
def allowed_methods_header
allowed_methods.map { |method_symbol| method_symbol.to_s.upcase } * ', '
end
-
- def handle_response!(response)
- response.headers['Allow'] ||= allowed_methods_header
- end
end
class NotImplemented < MethodNotAllowed #:nodoc:
@@ -510,9 +506,8 @@ module ActionController #:nodoc:
public
def call(env)
- # HACK: For global rescue to have access to the original request and response
- request = env["action_dispatch.rescue.request"] ||= ActionDispatch::Request.new(env)
- response = env["action_dispatch.rescue.response"] ||= ActionDispatch::Response.new
+ request = ActionDispatch::Request.new(env)
+ response = ActionDispatch::Response.new
process(request, response).to_a
end
diff --git a/actionpack/lib/action_controller/base/rescue.rb b/actionpack/lib/action_controller/base/rescue.rb
new file mode 100644
index 0000000000..2717a06a37
--- /dev/null
+++ b/actionpack/lib/action_controller/base/rescue.rb
@@ -0,0 +1,50 @@
+module ActionController #:nodoc:
+ # Actions that fail to perform as expected throw exceptions. These
+ # exceptions can either be rescued for the public view (with a nice
+ # user-friendly explanation) or for the developers view (with tons of
+ # debugging information). The developers view is already implemented by
+ # the Action Controller, but the public view should be tailored to your
+ # specific application.
+ #
+ # The default behavior for public exceptions is to render a static html
+ # file with the name of the error code thrown. If no such file exists, an
+ # empty response is sent with the correct status code.
+ #
+ # You can override what constitutes a local request by overriding the
+ # <tt>local_request?</tt> method in your own controller. Custom rescue
+ # behavior is achieved by overriding the <tt>rescue_action_in_public</tt>
+ # and <tt>rescue_action_locally</tt> methods.
+ module Rescue
+ def self.included(base) #:nodoc:
+ base.send :include, ActiveSupport::Rescuable
+ base.extend(ClassMethods)
+
+ base.class_eval do
+ alias_method_chain :perform_action, :rescue
+ end
+ end
+
+ module ClassMethods
+ def rescue_action(env)
+ exception = env.delete('action_dispatch.rescue.exception')
+ request = ActionDispatch::Request.new(env)
+ response = ActionDispatch::Response.new
+ new.process(request, response, :rescue_action, exception).to_a
+ end
+ end
+
+ protected
+ # Exception handler called when the performance of an action raises
+ # an exception.
+ def rescue_action(exception)
+ rescue_with_handler(exception) || raise(exception)
+ end
+
+ private
+ def perform_action_with_rescue
+ perform_action_without_rescue
+ rescue Exception => exception
+ rescue_action(exception)
+ end
+ end
+end
diff --git a/actionpack/lib/action_controller/dispatch/dispatcher.rb b/actionpack/lib/action_controller/dispatch/dispatcher.rb
index 25844bf2a2..c0eb359547 100644
--- a/actionpack/lib/action_controller/dispatch/dispatcher.rb
+++ b/actionpack/lib/action_controller/dispatch/dispatcher.rb
@@ -75,18 +75,10 @@ module ActionController
end
def _call(env)
- begin
- run_callbacks :before_dispatch
- Routing::Routes.call(env)
- rescue Exception => exception
- if controller ||= (::ApplicationController rescue Base)
- controller.call_with_exception(env, exception)
- else
- raise exception
- end
- ensure
- run_callbacks :after_dispatch, :enumerator => :reverse_each
- end
+ run_callbacks :before_dispatch
+ Routing::Routes.call(env)
+ ensure
+ run_callbacks :after_dispatch, :enumerator => :reverse_each
end
def flush_logger
diff --git a/actionpack/lib/action_controller/dispatch/middlewares.rb b/actionpack/lib/action_controller/dispatch/middlewares.rb
index b5adbae746..31a7b00d28 100644
--- a/actionpack/lib/action_controller/dispatch/middlewares.rb
+++ b/actionpack/lib/action_controller/dispatch/middlewares.rb
@@ -3,6 +3,11 @@ use "Rack::Lock", :if => lambda {
}
use "ActionDispatch::Failsafe"
+use "ActionDispatch::ShowExceptions", lambda { ActionController::Base.consider_all_requests_local }
+use "ActionDispatch::Rescue", lambda {
+ controller = (::ApplicationController rescue ActionController::Base)
+ controller.method(:rescue_action)
+}
use lambda { ActionController::Base.session_store },
lambda { ActionController::Base.session_options }
diff --git a/actionpack/lib/action_controller/dispatch/rescue.rb b/actionpack/lib/action_controller/dispatch/rescue.rb
deleted file mode 100644
index 2f3b40c231..0000000000
--- a/actionpack/lib/action_controller/dispatch/rescue.rb
+++ /dev/null
@@ -1,185 +0,0 @@
-module ActionController #:nodoc:
- # Actions that fail to perform as expected throw exceptions. These
- # exceptions can either be rescued for the public view (with a nice
- # user-friendly explanation) or for the developers view (with tons of
- # debugging information). The developers view is already implemented by
- # the Action Controller, but the public view should be tailored to your
- # specific application.
- #
- # The default behavior for public exceptions is to render a static html
- # file with the name of the error code thrown. If no such file exists, an
- # empty response is sent with the correct status code.
- #
- # You can override what constitutes a local request by overriding the
- # <tt>local_request?</tt> method in your own controller. Custom rescue
- # behavior is achieved by overriding the <tt>rescue_action_in_public</tt>
- # and <tt>rescue_action_locally</tt> methods.
- module Rescue
- LOCALHOST = '127.0.0.1'.freeze
-
- DEFAULT_RESCUE_RESPONSE = :internal_server_error
- DEFAULT_RESCUE_RESPONSES = {
- 'ActionController::RoutingError' => :not_found,
- 'ActionController::UnknownAction' => :not_found,
- 'ActiveRecord::RecordNotFound' => :not_found,
- 'ActiveRecord::StaleObjectError' => :conflict,
- 'ActiveRecord::RecordInvalid' => :unprocessable_entity,
- 'ActiveRecord::RecordNotSaved' => :unprocessable_entity,
- 'ActionController::MethodNotAllowed' => :method_not_allowed,
- 'ActionController::NotImplemented' => :not_implemented,
- 'ActionController::InvalidAuthenticityToken' => :unprocessable_entity
- }
-
- DEFAULT_RESCUE_TEMPLATE = 'diagnostics'
- DEFAULT_RESCUE_TEMPLATES = {
- 'ActionView::MissingTemplate' => 'missing_template',
- 'ActionController::RoutingError' => 'routing_error',
- 'ActionController::UnknownAction' => 'unknown_action',
- 'ActionView::TemplateError' => 'template_error'
- }
-
- RESCUES_TEMPLATE_PATH = ActionView::Template::FileSystemPath.new(
- File.join(File.dirname(__FILE__), "templates"))
-
- def self.included(base) #:nodoc:
- base.cattr_accessor :rescue_responses
- base.rescue_responses = Hash.new(DEFAULT_RESCUE_RESPONSE)
- base.rescue_responses.update DEFAULT_RESCUE_RESPONSES
-
- base.cattr_accessor :rescue_templates
- base.rescue_templates = Hash.new(DEFAULT_RESCUE_TEMPLATE)
- base.rescue_templates.update DEFAULT_RESCUE_TEMPLATES
-
- base.extend(ClassMethods)
- base.send :include, ActiveSupport::Rescuable
-
- base.class_eval do
- alias_method_chain :perform_action, :rescue
- end
- end
-
- module ClassMethods
- def call_with_exception(env, exception) #:nodoc:
- request = env["action_controller.rescue.request"] ||= ActionDispatch::Request.new(env)
- response = env["action_controller.rescue.response"] ||= ActionDispatch::Response.new
- new.process(request, response, :rescue_action, exception).to_a
- end
- end
-
- protected
- # Exception handler called when the performance of an action raises
- # an exception.
- def rescue_action(exception)
- rescue_with_handler(exception) ||
- rescue_action_without_handler(exception)
- end
-
- # Overwrite to implement custom logging of errors. By default
- # logs as fatal.
- def log_error(exception) #:doc:
- ActiveSupport::Deprecation.silence do
- if ActionView::TemplateError === exception
- logger.fatal(exception.to_s)
- else
- logger.fatal(
- "\n#{exception.class} (#{exception.message}):\n " +
- clean_backtrace(exception).join("\n ") + "\n\n"
- )
- end
- end
- end
-
- # Overwrite to implement public exception handling (for requests
- # answering false to <tt>local_request?</tt>). By default will call
- # render_optional_error_file. Override this method to provide more
- # user friendly error messages.
- def rescue_action_in_public(exception) #:doc:
- render_optional_error_file response_code_for_rescue(exception)
- end
-
- # Attempts to render a static error page based on the
- # <tt>status_code</tt> thrown, or just return headers if no such file
- # exists. At first, it will try to render a localized static page.
- # For example, if a 500 error is being handled Rails and locale is :da,
- # it will first attempt to render the file at <tt>public/500.da.html</tt>
- # then attempt to render <tt>public/500.html</tt>. If none of them exist,
- # the body of the response will be left empty.
- def render_optional_error_file(status_code)
- status = interpret_status(status_code)
- locale_path = "#{Rails.public_path}/#{status[0,3]}.#{I18n.locale}.html" if I18n.locale
- path = "#{Rails.public_path}/#{status[0,3]}.html"
-
- if locale_path && File.exist?(locale_path)
- render :file => locale_path, :status => status, :content_type => Mime::HTML
- elsif File.exist?(path)
- render :file => path, :status => status, :content_type => Mime::HTML
- else
- head status
- end
- end
-
- # True if the request came from localhost, 127.0.0.1. Override this
- # method if you wish to redefine the meaning of a local request to
- # include remote IP addresses or other criteria.
- def local_request? #:doc:
- request.remote_addr == LOCALHOST && request.remote_ip == LOCALHOST
- end
-
- # Render detailed diagnostics for unhandled exceptions rescued from
- # a controller action.
- def rescue_action_locally(exception)
- @template.instance_variable_set("@exception", exception)
- @template.instance_variable_set("@rescues_path", RESCUES_TEMPLATE_PATH)
- @template.instance_variable_set("@contents",
- @template._render_template(template_path_for_local_rescue(exception)))
-
- response.content_type = Mime::HTML
- response.status = interpret_status(response_code_for_rescue(exception))
-
- content = @template._render_template(rescues_path("layout"))
- render_for_text(content)
- end
-
- def rescue_action_without_handler(exception)
- log_error(exception) if logger
- erase_results if performed?
-
- # Let the exception alter the response if it wants.
- # For example, MethodNotAllowed sets the Allow header.
- if exception.respond_to?(:handle_response!)
- exception.handle_response!(response)
- end
-
- if consider_all_requests_local || local_request?
- rescue_action_locally(exception)
- else
- rescue_action_in_public(exception)
- end
- end
-
- private
- def perform_action_with_rescue #:nodoc:
- perform_action_without_rescue
- rescue Exception => exception
- rescue_action(exception)
- end
-
- def rescues_path(template_name)
- RESCUES_TEMPLATE_PATH.find_by_parts("rescues/#{template_name}.erb")
- end
-
- def template_path_for_local_rescue(exception)
- rescues_path(rescue_templates[exception.class.name])
- end
-
- def response_code_for_rescue(exception)
- rescue_responses[exception.class.name]
- end
-
- def clean_backtrace(exception)
- defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) ?
- Rails.backtrace_cleaner.clean(exception.backtrace) :
- exception.backtrace
- end
- end
-end
diff --git a/actionpack/lib/action_controller/dispatch/templates/rescues/diagnostics.erb b/actionpack/lib/action_controller/dispatch/templates/rescues/diagnostics.erb
deleted file mode 100644
index e5c647c826..0000000000
--- a/actionpack/lib/action_controller/dispatch/templates/rescues/diagnostics.erb
+++ /dev/null
@@ -1,10 +0,0 @@
-<h1>
- <%=h @exception.class.to_s %>
- <% if request.parameters['controller'] %>
- in <%=h request.parameters['controller'].humanize %>Controller<% if request.parameters['action'] %>#<%=h request.parameters['action'] %><% end %>
- <% end %>
-</h1>
-<pre><%=h @exception.clean_message %></pre>
-
-<%= @template._render_template(@rescues_path.find_by_parts("rescues/_trace.erb")) %>
-<%= @template._render_template(@rescues_path.find_by_parts("rescues/_request_and_response.erb")) %> \ No newline at end of file
diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb
index 5f6202d153..5a082fa7e3 100644
--- a/actionpack/lib/action_dispatch.rb
+++ b/actionpack/lib/action_dispatch.rb
@@ -48,6 +48,8 @@ module ActionDispatch
autoload :Failsafe, 'action_dispatch/middleware/failsafe'
autoload :ParamsParser, 'action_dispatch/middleware/params_parser'
autoload :Reloader, 'action_dispatch/middleware/reloader'
+ autoload :Rescue, 'action_dispatch/middleware/rescue'
+ autoload :ShowExceptions, 'action_dispatch/middleware/show_exceptions'
autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
autoload :Assertions, 'action_dispatch/testing/assertions'
diff --git a/actionpack/lib/action_dispatch/middleware/rescue.rb b/actionpack/lib/action_dispatch/middleware/rescue.rb
new file mode 100644
index 0000000000..1456825526
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/rescue.rb
@@ -0,0 +1,14 @@
+module ActionDispatch
+ class Rescue
+ def initialize(app, rescuer)
+ @app, @rescuer = app, rescuer
+ end
+
+ def call(env)
+ @app.call(env)
+ rescue Exception => exception
+ env['action_dispatch.rescue.exception'] = exception
+ @rescuer.call(env)
+ end
+ end
+end
diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
new file mode 100644
index 0000000000..791254cdf2
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
@@ -0,0 +1,142 @@
+module ActionDispatch
+ class ShowExceptions
+ include StatusCodes
+
+ LOCALHOST = '127.0.0.1'.freeze
+
+ DEFAULT_RESCUE_RESPONSE = :internal_server_error
+ DEFAULT_RESCUE_RESPONSES = {
+ 'ActionController::RoutingError' => :not_found,
+ 'ActionController::UnknownAction' => :not_found,
+ 'ActiveRecord::RecordNotFound' => :not_found,
+ 'ActiveRecord::StaleObjectError' => :conflict,
+ 'ActiveRecord::RecordInvalid' => :unprocessable_entity,
+ 'ActiveRecord::RecordNotSaved' => :unprocessable_entity,
+ 'ActionController::MethodNotAllowed' => :method_not_allowed,
+ 'ActionController::NotImplemented' => :not_implemented,
+ 'ActionController::InvalidAuthenticityToken' => :unprocessable_entity
+ }
+
+ DEFAULT_RESCUE_TEMPLATE = 'diagnostics'
+ DEFAULT_RESCUE_TEMPLATES = {
+ 'ActionView::MissingTemplate' => 'missing_template',
+ 'ActionController::RoutingError' => 'routing_error',
+ 'ActionController::UnknownAction' => 'unknown_action',
+ 'ActionView::TemplateError' => 'template_error'
+ }
+
+ RESCUES_TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates')
+
+ cattr_accessor :rescue_responses
+ @@rescue_responses = Hash.new(DEFAULT_RESCUE_RESPONSE)
+ @@rescue_responses.update DEFAULT_RESCUE_RESPONSES
+
+ cattr_accessor :rescue_templates
+ @@rescue_templates = Hash.new(DEFAULT_RESCUE_TEMPLATE)
+ @@rescue_templates.update DEFAULT_RESCUE_TEMPLATES
+
+ def initialize(app, consider_all_requests_local = false)
+ @app = app
+ @consider_all_requests_local = consider_all_requests_local
+ end
+
+ def call(env)
+ @app.call(env)
+ rescue Exception => exception
+ log_error(exception) if logger
+
+ request = Request.new(env)
+ if @consider_all_requests_local || local_request?(request)
+ rescue_action_locally(request, exception)
+ else
+ rescue_action_in_public(exception)
+ end
+ end
+
+ private
+ # Render detailed diagnostics for unhandled exceptions rescued from
+ # a controller action.
+ def rescue_action_locally(request, exception)
+ template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
+ :template => template,
+ :request => request,
+ :exception => exception
+ )
+ file = "rescues/#{@@rescue_templates[exception.class.name]}.erb"
+ body = template.render(:file => file, :layout => 'rescues/layout.erb')
+
+ headers = {'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s}
+ status = status_code(exception)
+
+ [status, headers, body]
+ end
+
+ # Attempts to render a static error page based on the
+ # <tt>status_code</tt> thrown, or just return headers if no such file
+ # exists. At first, it will try to render a localized static page.
+ # For example, if a 500 error is being handled Rails and locale is :da,
+ # it will first attempt to render the file at <tt>public/500.da.html</tt>
+ # then attempt to render <tt>public/500.html</tt>. If none of them exist,
+ # the body of the response will be left empty.
+ def rescue_action_in_public(exception)
+ status = status_code(exception)
+ locale_path = "#{public_path}/#{status}.#{I18n.locale}.html" if I18n.locale
+ path = "#{public_path}/#{status}.html"
+
+ if locale_path && File.exist?(locale_path)
+ render_public_file(status, locale_path)
+ elsif File.exist?(path)
+ render_public_file(status, path)
+ else
+ [status, {'Content-Type' => 'text/html', 'Content-Length' => '0'}, []]
+ end
+ end
+
+ # True if the request came from localhost, 127.0.0.1.
+ def local_request?(request)
+ request.remote_addr == LOCALHOST && request.remote_ip == LOCALHOST
+ end
+
+ def render_public_file(status, path)
+ body = File.read(path)
+ [status, {'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s}, body]
+ end
+
+ def status_code(exception)
+ interpret_status(@@rescue_responses[exception.class.name]).to_i
+ end
+
+ def public_path
+ if defined?(Rails)
+ Rails.public_path
+ else
+ "public"
+ end
+ end
+
+ def log_error(exception) #:doc:
+ ActiveSupport::Deprecation.silence do
+ if ActionView::TemplateError === exception
+ logger.fatal(exception.to_s)
+ else
+ logger.fatal(
+ "\n#{exception.class} (#{exception.message}):\n " +
+ clean_backtrace(exception).join("\n ") + "\n\n"
+ )
+ end
+ end
+ end
+
+ def clean_backtrace(exception)
+ defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) ?
+ Rails.backtrace_cleaner.clean(exception.backtrace) :
+ exception.backtrace
+ end
+
+ def logger
+ if defined?(Rails.logger)
+ Rails.logger
+ end
+ end
+ end
+end
diff --git a/actionpack/lib/action_controller/dispatch/templates/rescues/_request_and_response.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
index 64b34650b1..5224403dab 100644
--- a/actionpack/lib/action_controller/dispatch/templates/rescues/_request_and_response.erb
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
@@ -6,7 +6,7 @@
<% end %>
<%
- clean_params = request.parameters.clone
+ clean_params = @request.parameters.clone
clean_params.delete("action")
clean_params.delete("controller")
@@ -17,8 +17,8 @@
<p><b>Parameters</b>: <pre><%=h request_dump %></pre></p>
<p><a href="#" onclick="document.getElementById('session_dump').style.display='block'; return false;">Show session dump</a></p>
-<div id="session_dump" style="display:none"><%= debug(request.session.instance_variable_get("@data")) %></div>
+<div id="session_dump" style="display:none"><%= debug(@request.session.instance_variable_get("@data")) %></div>
<h2 style="margin-top: 30px">Response</h2>
-<p><b>Headers</b>: <pre><%=h response ? response.headers.inspect.gsub(',', ",\n") : 'None' %></pre></p>
+<p><b>Headers</b>: <pre><%=h @response ? @response.headers.inspect.gsub(',', ",\n") : 'None' %></pre></p>
diff --git a/actionpack/lib/action_controller/dispatch/templates/rescues/_trace.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
index bb2d8375bd..bb2d8375bd 100644
--- a/actionpack/lib/action_controller/dispatch/templates/rescues/_trace.erb
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
new file mode 100644
index 0000000000..693e56270a
--- /dev/null
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
@@ -0,0 +1,10 @@
+<h1>
+ <%=h @exception.class.to_s %>
+ <% if @request.parameters['controller'] %>
+ in <%=h @request.parameters['controller'].humanize %>Controller<% if @request.parameters['action'] %>#<%=h @request.parameters['action'] %><% end %>
+ <% end %>
+</h1>
+<pre><%=h @exception.clean_message %></pre>
+
+<%= render :file => "rescues/_trace.erb" %>
+<%= render :file => "rescues/_request_and_response.erb" %>
diff --git a/actionpack/lib/action_controller/dispatch/templates/rescues/layout.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb
index 4a04742e40..6c32fb17b8 100644
--- a/actionpack/lib/action_controller/dispatch/templates/rescues/layout.erb
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb
@@ -23,7 +23,7 @@
</head>
<body>
-<%= @contents %>
+<%= yield %>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/actionpack/lib/action_controller/dispatch/templates/rescues/missing_template.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.erb
index dbfdf76947..dbfdf76947 100644
--- a/actionpack/lib/action_controller/dispatch/templates/rescues/missing_template.erb
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_template.erb
diff --git a/actionpack/lib/action_controller/dispatch/templates/rescues/routing_error.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
index ccfa858cce..ccfa858cce 100644
--- a/actionpack/lib/action_controller/dispatch/templates/rescues/routing_error.erb
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
diff --git a/actionpack/lib/action_controller/dispatch/templates/rescues/template_error.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb
index 2e34e03bd5..02fa18211d 100644
--- a/actionpack/lib/action_controller/dispatch/templates/rescues/template_error.erb
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/template_error.erb
@@ -1,6 +1,6 @@
<h1>
<%=h @exception.original_exception.class.to_s %> in
- <%=h request.parameters["controller"].capitalize if request.parameters["controller"]%>#<%=h request.parameters["action"] %>
+ <%=h @request.parameters["controller"].capitalize if @request.parameters["controller"]%>#<%=h @request.parameters["action"] %>
</h1>
<p>
@@ -15,7 +15,7 @@
<% @real_exception = @exception
@exception = @exception.original_exception || @exception %>
-<%= render :file => @rescues_path["rescues/_trace.erb"] %>
+<%= render :file => "rescues/_trace.erb" %>
<% @exception = @real_exception %>
-<%= render :file => @rescues_path["rescues/_request_and_response.erb"] %>
+<%= render :file => "rescues/_request_and_response.erb" %>
diff --git a/actionpack/lib/action_controller/dispatch/templates/rescues/unknown_action.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb
index 683379da10..683379da10 100644
--- a/actionpack/lib/action_controller/dispatch/templates/rescues/unknown_action.erb
+++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb
diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb
index 92e3da580e..501a7c4dfb 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/response.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb
@@ -31,13 +31,7 @@ module ActionDispatch
elsif type.is_a?(Symbol) && @response.response_code == ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[type]
assert_block("") { true } # to count the assertion
else
- if @controller && @response.error?
- exception = @controller.template.instance_variable_get(:@exception)
- exception_message = exception && exception.message
- assert_block(build_message(message, "Expected response to be a <?>, but was <?>\n<?>", type, @response.response_code, exception_message.to_s)) { false }
- else
- assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false }
- end
+ assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false }
end
end