Skip to content

Commit c2ed23d

Browse files
committed
Retry middleware, exceptions option should handle string exception class name consistently (lostisland#1334)
1 parent 26b1536 commit c2ed23d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/faraday/request/retry.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class << matcher
184184
if ex.is_a? Module
185185
error.is_a? ex
186186
else
187-
error.class.to_s == ex.to_s
187+
Object.const_defined?(ex.to_s) && error.is_a?(Object.const_get(ex.to_s))
188188
end
189189
end
190190
end

spec/faraday/request/retry_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@
3232

3333
it { expect(times_called).to eq(3) }
3434
end
35+
36+
context 'and this is passed as a string custom exception' do
37+
let(:options) { [{ exceptions: 'StandardError' }] }
38+
39+
it { expect(times_called).to eq(3) }
40+
end
41+
42+
context 'and a non-existent string custom exception is passed' do
43+
let(:options) { [{ exceptions: 'WrongStandardErrorNotExisting' }] }
44+
45+
it { expect(times_called).to eq(1) }
46+
end
3547
end
3648

3749
context 'when an expected error happens' do

0 commit comments

Comments
 (0)