@@ -125,31 +125,23 @@ def redefine_method
125
125
# function. Otherwise we return the result.
126
126
# If we run out of functions, we raise the last error, but
127
127
# convert it to_contract_error.
128
- success = false
129
- i = 0
130
- result = nil
128
+
131
129
expected_error = decorated_methods [ 0 ] . failure_exception
130
+ last_error = nil
132
131
133
- until success
134
- decorated_method = decorated_methods [ i ]
135
- i += 1
136
- begin
137
- success = true
138
- result = decorated_method . call_with ( self , *args , &blk )
139
- rescue expected_error => error
140
- success = false
141
- unless decorated_methods [ i ]
142
- begin
143
- ::Contract . failure_callback ( error . data , false )
144
- rescue expected_error => final_error
145
- raise final_error . to_contract_error
146
- end
147
- end
148
- end
132
+ decorated_methods . each do |decorated_method |
133
+ result = decorated_method . call_with_inner ( true , self , *args , &blk )
134
+ return result unless result . is_a? ( ParamContractError )
135
+ last_error = result
149
136
end
150
137
151
- # Return the result of successfully called method
152
- result
138
+ begin
139
+ if ::Contract . failure_callback ( last_error . data , false )
140
+ decorated_methods . last . call_with_inner ( false , self , *args , &blk )
141
+ end
142
+ rescue expected_error => final_error
143
+ raise final_error . to_contract_error
144
+ end
153
145
end
154
146
end
155
147
0 commit comments