From f4c0e703a943143abb4d8c17bae699ffe659912a Mon Sep 17 00:00:00 2001 From: Dariusz Musielak Date: Mon, 20 Dec 2021 21:21:30 +0100 Subject: [PATCH 1/3] Add default value to exc in Faraday::Error initialize in specs we only sets nil, missing default value in specific circumentances raised ArgumentError for Faraday::ConnectionFailed. It was difficult to spot why. I would like to have this change to do not worry about cases like this: https://stackoverflow.com/questions/59176256/unexpected-behaviour-with-faradayconnectionfailed/70427415#70427415 --- lib/faraday/error.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/faraday/error.rb b/lib/faraday/error.rb index f23065f29..c543c5ccc 100644 --- a/lib/faraday/error.rb +++ b/lib/faraday/error.rb @@ -6,7 +6,7 @@ module Faraday class Error < StandardError attr_reader :response, :wrapped_exception - def initialize(exc, response = nil) + def initialize(exc = nil, response = nil) @wrapped_exception = nil unless defined?(@wrapped_exception) @response = nil unless defined?(@response) super(exc_msg_and_response!(exc, response)) From 5d69b95cb820fcbda0277e459d63f191730ae0b1 Mon Sep 17 00:00:00 2001 From: Dariusz Musielak Date: Mon, 20 Dec 2021 21:22:10 +0100 Subject: [PATCH 2/3] Update specs where we use Faraday::ConnectionFailed --- examples/client_spec.rb | 2 +- examples/client_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/client_spec.rb b/examples/client_spec.rb index 647bcf81e..99a527793 100644 --- a/examples/client_spec.rb +++ b/examples/client_spec.rb @@ -56,7 +56,7 @@ def sushi(jname, params: {}) it 'handles exception' do stubs.get('/ebi') do - raise Faraday::ConnectionFailed, nil + raise Faraday::ConnectionFailed end expect { client.sushi('ebi') }.to raise_error(Faraday::ConnectionFailed) diff --git a/examples/client_test.rb b/examples/client_test.rb index e65607d00..ed477fa5e 100644 --- a/examples/client_test.rb +++ b/examples/client_test.rb @@ -60,7 +60,7 @@ def test_sushi_not_found def test_sushi_exception stubs = Faraday::Adapter::Test::Stubs.new stubs.get('/ebi') do - raise Faraday::ConnectionFailed, nil + raise Faraday::ConnectionFailed end cli = client(stubs) From 67a5050c15759df1aa309524c60be439d381309a Mon Sep 17 00:00:00 2001 From: Dariusz Musielak Date: Mon, 20 Dec 2021 21:22:26 +0100 Subject: [PATCH 3/3] Update docs --- docs/adapters/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/adapters/testing.md b/docs/adapters/testing.md index 7f7c66ec1..4d28c3959 100644 --- a/docs/adapters/testing.md +++ b/docs/adapters/testing.md @@ -33,7 +33,7 @@ conn = Faraday.new do |builder| # test exceptions too stub.get('/boom') do - raise Faraday::ConnectionFailed, nil + raise Faraday::ConnectionFailed end end end