public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Allow Dispatcher exceptions to be handled in application.rb using rescue_from
lifo (author)
Wed Jul 16 10:51:40 -0700 2008
commit  90c930f45c5c6766306929241462ffff8f67b86e
tree    0c8a34193358991700b5142afdb4386af3d09d3b
parent  c64d749abdf31a2be322b1787165024067abbda7
...
112
113
114
115
116
 
 
 
 
 
117
118
119
120
121
122
 
 
 
 
 
123
124
125
126
127
 
 
 
 
 
128
129
130
...
200
201
202
203
 
204
205
206
...
112
113
114
 
 
115
116
117
118
119
120
 
 
 
 
 
121
122
123
124
125
126
 
 
 
 
127
128
129
130
131
132
133
134
...
204
205
206
 
207
208
209
210
0
@@ -112,19 +112,23 @@ module ActionController #:nodoc:
0
     protected
0
       # Exception handler called when the performance of an action raises an exception.
0
       def rescue_action(exception)
0
-        log_error(exception) if logger
0
-        erase_results if performed?
0
+        if handler_for_rescue(exception)
0
+          rescue_action_with_handler(exception)
0
+        else
0
+          log_error(exception) if logger
0
+          erase_results if performed?
0
 
0
-        # Let the exception alter the response if it wants.
0
-        # For example, MethodNotAllowed sets the Allow header.
0
-        if exception.respond_to?(:handle_response!)
0
-          exception.handle_response!(response)
0
-        end
0
+          # Let the exception alter the response if it wants.
0
+          # For example, MethodNotAllowed sets the Allow header.
0
+          if exception.respond_to?(:handle_response!)
0
+            exception.handle_response!(response)
0
+          end
0
 
0
-        if consider_all_requests_local || local_request?
0
-          rescue_action_locally(exception)
0
-        else
0
-          rescue_action_in_public(exception)
0
+          if consider_all_requests_local || local_request?
0
+            rescue_action_locally(exception)
0
+          else
0
+            rescue_action_in_public(exception)
0
+          end
0
         end
0
       end
0
 
0
@@ -200,7 +204,7 @@ module ActionController #:nodoc:
0
       def perform_action_with_rescue #:nodoc:
0
         perform_action_without_rescue
0
       rescue Exception => exception
0
-        rescue_action_with_handler(exception) || rescue_action(exception)
0
+        rescue_action(exception)
0
       end
0
 
0
       def rescues_path(template_name)
...
62
63
64
 
 
 
 
 
65
66
67
...
378
379
380
 
 
 
 
381
382
383
...
62
63
64
65
66
67
68
69
70
71
72
...
383
384
385
386
387
388
389
390
391
392
0
@@ -62,6 +62,11 @@ class RescueController < ActionController::Base
0
     render :text => exception.message
0
   end
0
 
0
+  # This is a Dispatcher exception and should be in ApplicationController.
0
+  rescue_from ActionController::RoutingError do
0
+    render :text => 'no way'
0
+  end
0
+
0
   def raises
0
     render :text => 'already rendered'
0
     raise "don't panic!"
0
@@ -378,6 +383,10 @@ class RescueTest < Test::Unit::TestCase
0
     assert_equal "RescueController::ResourceUnavailableToRescueAsString", @response.body
0
   end
0
 
0
+  def test_rescue_dispatcher_exceptions
0
+    RescueController.process_with_exception(@request, @response, ActionController::RoutingError.new("Route not found"))
0
+    assert_equal "no way", @response.body
0
+  end
0
 
0
   protected
0
     def with_all_requests_local(local = true)

Comments