2009-05-15 20:49:11 -04:00
|
|
|
module ActionController #:nodoc:
|
2011-12-16 04:38:17 -05:00
|
|
|
# This module is responsible to provide `rescue_from` helpers
|
|
|
|
# to controllers and configure when detailed exceptions must be
|
|
|
|
# shown.
|
2009-05-15 20:49:11 -04:00
|
|
|
module Rescue
|
2009-05-28 12:35:36 -04:00
|
|
|
extend ActiveSupport::Concern
|
2009-09-15 11:05:46 -04:00
|
|
|
include ActiveSupport::Rescuable
|
2009-05-15 20:49:11 -04:00
|
|
|
|
2010-07-19 08:49:20 -04:00
|
|
|
def rescue_with_handler(exception)
|
2010-07-19 12:03:20 -04:00
|
|
|
if (exception.respond_to?(:original_exception) &&
|
|
|
|
(orig_exception = exception.original_exception) &&
|
|
|
|
handler_for_rescue(orig_exception))
|
2010-07-19 08:49:20 -04:00
|
|
|
exception = orig_exception
|
|
|
|
end
|
|
|
|
super(exception)
|
|
|
|
end
|
|
|
|
|
2011-12-16 04:38:17 -05:00
|
|
|
# Override this method if you want to customize when detailed
|
|
|
|
# exceptions must be shown. This method is only called when
|
|
|
|
# consider_all_requests_local is false. By default, it returns
|
|
|
|
# false, but someone may set it to `request.local?` so local
|
|
|
|
# requests in production still shows the detailed exception pages.
|
2011-11-22 05:34:13 -05:00
|
|
|
def show_detailed_exceptions?
|
2011-12-16 04:38:17 -05:00
|
|
|
false
|
2011-11-22 05:34:13 -05:00
|
|
|
end
|
|
|
|
|
2009-05-28 10:49:02 -04:00
|
|
|
private
|
2009-09-15 11:05:46 -04:00
|
|
|
def process_action(*args)
|
2009-05-28 10:49:02 -04:00
|
|
|
super
|
|
|
|
rescue Exception => exception
|
2011-12-15 13:43:49 -05:00
|
|
|
request.env['action_dispatch.show_detailed_exceptions'] ||= show_detailed_exceptions?
|
2009-09-15 11:05:46 -04:00
|
|
|
rescue_with_handler(exception) || raise(exception)
|
2009-05-28 10:49:02 -04:00
|
|
|
end
|
2009-05-15 20:49:11 -04:00
|
|
|
end
|
|
|
|
end
|