0
@@ -41,10 +41,9 @@ module ActionController #:nodoc:
0
base.rescue_templates = Hash.new(DEFAULT_RESCUE_TEMPLATE)
0
base.rescue_templates.update DEFAULT_RESCUE_TEMPLATES
0
- base.class_inheritable_array :rescue_handlers
0
- base.rescue_handlers = []
0
base.extend(ClassMethods)
0
+ base.send :include, ActiveSupport::Rescuable
0
alias_method_chain :perform_action, :rescue
0
@@ -54,65 +53,12 @@ module ActionController #:nodoc:
0
def process_with_exception(request, response, exception) #:nodoc:
0
new.process(request, response, :rescue_action, exception)
0
- # Rescue exceptions raised in controller actions.
0
- # <tt>rescue_from</tt> receives a series of exception classes or class
0
- # names, and a trailing <tt>:with</tt> option with the name of a method
0
- # or a Proc object to be called to handle them. Alternatively a block can
0
- # Handlers that take one argument will be called with the exception, so
0
- # that the exception can be inspected when dealing with it.
0
- # Handlers are inherited. They are searched from right to left, from
0
- # bottom to top, and up the hierarchy. The handler of the first class for
0
- # which <tt>exception.is_a?(klass)</tt> holds true is the one invoked, if
0
- # class ApplicationController < ActionController::Base
0
- # rescue_from User::NotAuthorized, :with => :deny_access # self defined exception
0
- # rescue_from ActiveRecord::RecordInvalid, :with => :show_errors
0
- # rescue_from 'MyAppError::Base' do |exception|
0
- # render :xml => exception, :status => 500
0
- # def show_errors(exception)
0
- # exception.record.new_record? ? ...
0
- def rescue_from(*klasses, &block)
0
- options = klasses.extract_options!
0
- unless options.has_key?(:with)
0
- block_given? ? options[:with] = block : raise(ArgumentError, "Need a handler. Supply an options hash that has a :with key as the last argument.")
0
- klasses.each do |klass|
0
- key = if klass.is_a?(Class) && klass <= Exception
0
- elsif klass.is_a?(String)
0
- raise(ArgumentError, "#{klass} is neither an Exception nor a String")
0
- # Order is important, we put the pair at the end. When dealing with an
0
- # exception we will follow the documented order going from right to left.
0
- rescue_handlers << [key, options[:with]]
0
# Exception handler called when the performance of an action raises an exception.
0
def rescue_action(exception)
0
- rescue_
action_with_handler(exception) || rescue_action_without_handler(exception)
0
+ rescue_
with_handler(exception) || rescue_action_without_handler(exception)
0
# Overwrite to implement custom logging of errors. By default logs as fatal.
0
@@ -168,18 +114,6 @@ module ActionController #:nodoc:
0
render_for_file(rescues_path("layout"), response_code_for_rescue(exception))
0
- # Tries to rescue the exception by looking up and calling a registered handler.
0
- def rescue_action_with_handler(exception)
0
- if handler = handler_for_rescue(exception)
0
- handler.call(exception)
0
- true # don't rely on the return value of the handler
0
def rescue_action_without_handler(exception)
0
log_error(exception) if logger
0
erase_results if performed?
0
@@ -216,36 +150,6 @@ module ActionController #:nodoc:
0
rescue_responses[exception.class.name]
0
- def handler_for_rescue(exception)
0
- # We go from right to left because pairs are pushed onto rescue_handlers
0
- # as rescue_from declarations are found.
0
- _, handler = *rescue_handlers.reverse.detect do |klass_name, handler|
0
- # The purpose of allowing strings in rescue_from is to support the
0
- # declaration of handler associations for exception classes whose
0
- # definition is yet unknown.
0
- # Since this loop needs the constants it would be inconsistent to
0
- # assume they should exist at this point. An early raised exception
0
- # could trigger some other handler and the array could include
0
- # precisely a string whose corresponding constant has not yet been
0
- # seen. This is why we are tolerant to unknown constants.
0
- # Note that this tolerance only matters if the exception was given as
0
- # a string, otherwise a NameError will be raised by the interpreter
0
- # itself when rescue_from CONSTANT is executed.
0
- klass = self.class.const_get(klass_name) rescue nil
0
- klass ||= klass_name.constantize rescue nil
0
- exception.is_a?(klass) if klass
0
def clean_backtrace(exception)
0
if backtrace = exception.backtrace
0
if defined?(RAILS_ROOT)