From 270f1bf660be5f1f3ea4d1e3a78fdd598106b352 Mon Sep 17 00:00:00 2001 From: Jonathan Rochkind Date: Mon, 11 Oct 2021 10:01:10 -0400 Subject: [PATCH] Retry middleware, exceptions option should handle string exception class name consistently Closes #1330 --- lib/faraday/request/retry.rb | 2 +- spec/faraday/request/retry_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/faraday/request/retry.rb b/lib/faraday/request/retry.rb index 3ba50b7a0..6fac9bba0 100644 --- a/lib/faraday/request/retry.rb +++ b/lib/faraday/request/retry.rb @@ -184,7 +184,7 @@ class << matcher if ex.is_a? Module error.is_a? ex else - error.class.to_s == ex.to_s + Object.const_defined?(ex.to_s) && error.is_a?(Object.const_get(ex.to_s)) end end end diff --git a/spec/faraday/request/retry_spec.rb b/spec/faraday/request/retry_spec.rb index 5891b73bc..b1399e18e 100644 --- a/spec/faraday/request/retry_spec.rb +++ b/spec/faraday/request/retry_spec.rb @@ -32,6 +32,18 @@ it { expect(times_called).to eq(3) } end + + context 'and this is passed as a string custom exception' do + let(:options) { [{ exceptions: 'StandardError' }] } + + it { expect(times_called).to eq(3) } + end + + context 'and a non-existent string custom exception is passed' do + let(:options) { [{ exceptions: 'WrongStandardErrorNotExisting' }] } + + it { expect(times_called).to eq(1) } + end end context 'when an expected error happens' do