From 52aeb8d2e72223f9b40b0193c151c252a3f4fb09 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 15 Sep 2009 16:33:15 -0500 Subject: Beef up AD::Rescue to replace global exception handling lost in ApplicationController --- actionpack/lib/action_dispatch/middleware/rescue.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_dispatch/middleware') diff --git a/actionpack/lib/action_dispatch/middleware/rescue.rb b/actionpack/lib/action_dispatch/middleware/rescue.rb index 1456825526..aee672112c 100644 --- a/actionpack/lib/action_dispatch/middleware/rescue.rb +++ b/actionpack/lib/action_dispatch/middleware/rescue.rb @@ -1,14 +1,26 @@ module ActionDispatch class Rescue - def initialize(app, rescuer) - @app, @rescuer = app, rescuer + def initialize(app, rescuers = {}, &block) + @app, @rescuers = app, {} + rescuers.each { |exception, rescuer| rescue_from(exception, rescuer) } + instance_eval(&block) if block_given? end def call(env) @app.call(env) rescue Exception => exception - env['action_dispatch.rescue.exception'] = exception - @rescuer.call(env) + if rescuer = @rescuers[exception.class.name] + env['action_dispatch.rescue.exception'] = exception + rescuer.call(env) + else + raise exception + end end + + protected + def rescue_from(exception, rescuer) + exception = exception.class.name if exception.is_a?(Exception) + @rescuers[exception.to_s] = rescuer + end end end -- cgit v1.2.3 From 81c421386c3989e96f1fd3b0370b75155eeda2e1 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 18 Sep 2009 10:35:42 -0700 Subject: 1.9 fix for changes to #to_s. By Sam Ruby. [#3228 state:resolved] --- .../lib/action_dispatch/middleware/templates/rescues/_trace.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_dispatch/middleware') diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb index bb2d8375bd..f8f6b424ca 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb @@ -15,12 +15,12 @@ show = "document.getElementById('#{name.gsub /\s/, '-'}').style.display='block';" hide = (names - [name]).collect {|hide_name| "document.getElementById('#{hide_name.gsub /\s/, '-'}').style.display='none';"} %> - <%= name %> <%= '|' unless names.last == name %> + <%= name %> <%= '|' unless names.last == name %> <% end %> <% traces.each do |name, trace| %>
;"> -
<%= trace.join "\n" %>
+
<%=h trace.join "\n" %>
<% end %> -- cgit v1.2.3