From f9edc079e030a5d2b0f21b80d6382caf10751057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 1 Dec 2011 21:15:42 +0100 Subject: Split and improve show and debug exceptions middlewares. --- .../action_dispatch/middleware/show_exceptions.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb index 346770acb7..c801bcf2ef 100644 --- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb @@ -3,8 +3,8 @@ require 'action_dispatch/middleware/exception_wrapper' require 'active_support/deprecation' module ActionDispatch - # This middleware rescues any exception returned by the application and renders - # nice exception pages if it's being rescued locally. + # This middleware rescues any exception returned by the application + # and wraps them in a format for the end user. class ShowExceptions RESCUES_TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates') @@ -40,11 +40,18 @@ module ActionDispatch raise exception if env['action_dispatch.show_exceptions'] == false end - response ? response : render_exception(env, exception) + response ? response : render_exception_with_failsafe(env, exception) end private + def render_exception_with_failsafe(env, exception) + render_exception(env, exception) + rescue Exception => failsafe_error + $stderr.puts "Error during failsafe response: #{failsafe_error}\n #{failsafe_error.backtrace * "\n "}" + FAILSAFE_RESPONSE + end + def render_exception(env, exception) wrapper = ExceptionWrapper.new(env, exception) @@ -59,13 +66,6 @@ module ActionDispatch else render(status, '') end - rescue Exception => failsafe_error - render_failsafe(failsafe_error) - end - - def render_failsafe(failsafe_error) - $stderr.puts "Error during failsafe response: #{failsafe_error}\n #{failsafe_error.backtrace * "\n "}" - FAILSAFE_RESPONSE end def render(status, body) @@ -73,7 +73,7 @@ module ActionDispatch end # TODO: Make this a middleware initialization parameter once - # we deprecated the second option + # we removed the second option (which is deprecated) def public_path defined?(Rails.public_path) ? Rails.public_path : 'public_path' end -- cgit v1.2.3