diff options
author | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-05-11 17:07:05 -0700 |
---|---|---|
committer | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-05-11 17:07:05 -0700 |
commit | 00a9d4b91cccdd88146cbe716eca844dcdfa08e7 (patch) | |
tree | 77398a4e98eb391258813fef47f1ecf57ae58972 /actionpack/lib/action_controller/base/rescue.rb | |
parent | 0f6e764e4060b75ea8a335e6971209a08bf8b40a (diff) | |
parent | 0cac68d3bed3e6bf8ec2eb994858e4a179046941 (diff) | |
download | rails-00a9d4b91cccdd88146cbe716eca844dcdfa08e7.tar.gz rails-00a9d4b91cccdd88146cbe716eca844dcdfa08e7.tar.bz2 rails-00a9d4b91cccdd88146cbe716eca844dcdfa08e7.zip |
Merge branch 'master' into wip_abstract_controller
Conflicts:
actionpack/lib/action_controller/abstract/callbacks.rb
actionpack/lib/action_controller/abstract/renderer.rb
actionpack/lib/action_controller/base/base.rb
actionpack/lib/action_controller/dispatch/dispatcher.rb
actionpack/lib/action_controller/routing/route_set.rb
actionpack/lib/action_controller/testing/process.rb
actionpack/test/abstract_controller/layouts_test.rb
actionpack/test/controller/filters_test.rb
actionpack/test/controller/helper_test.rb
actionpack/test/controller/render_test.rb
actionpack/test/new_base/test_helper.rb
Diffstat (limited to 'actionpack/lib/action_controller/base/rescue.rb')
-rw-r--r-- | actionpack/lib/action_controller/base/rescue.rb | 50 |
1 files changed, 50 insertions, 0 deletions
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 |