Skip to content

Commit 7a3be90

Browse files
committed
Refactor the handling of fallback exception handlers
1 parent 4331ee8 commit 7a3be90

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

activesupport/lib/active_support/rescuable.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ def rescue_from(*klasses, with: nil, &block)
8585
#
8686
# Returns the exception if it was handled and +nil+ if it was not.
8787
def rescue_with_handler(exception, object: self)
88-
handler, exception = handler_for_rescue(exception, object: object)
89-
if handler
88+
if handler = handler_for_rescue(exception, object: object)
9089
handler.call exception
9190
exception
91+
elsif exception
92+
rescue_with_handler(exception.cause, object: object)
9293
end
9394
end
9495

9596
def handler_for_rescue(exception, object: self) #:nodoc:
96-
rescuer, exception = find_rescue_handler(exception)
97-
result = case rescuer
97+
case rescuer = find_rescue_handler(exception)
9898
when Symbol
9999
method = object.method(rescuer)
100100
if method.arity == 0
@@ -109,7 +109,6 @@ def handler_for_rescue(exception, object: self) #:nodoc:
109109
-> e { object.instance_exec(e, &rescuer) }
110110
end
111111
end
112-
[result, exception]
113112
end
114113

115114
private
@@ -124,11 +123,7 @@ def find_rescue_handler(exception)
124123
end
125124
end
126125

127-
if handler
128-
[handler, exception]
129-
else
130-
find_rescue_handler(exception.cause)
131-
end
126+
handler
132127
end
133128
end
134129

0 commit comments

Comments
 (0)