diff --git a/CHANGELOG.md b/CHANGELOG.md index aaf28ab..b2bd101 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [Unreleased] +- Add rescue to SocketError exception; + ## [0.2.0] - 2023-05-22 - Add FService as runtime dependency. diff --git a/lib/f_http_client/processor/exception.rb b/lib/f_http_client/processor/exception.rb index 7db134d..fe157ca 100644 --- a/lib/f_http_client/processor/exception.rb +++ b/lib/f_http_client/processor/exception.rb @@ -29,6 +29,8 @@ def error_name case error.class.to_s when 'Errno::ECONNREFUSED' :connection_refused + when 'SocketError' + :connection_error when /timeout/i :timeout else diff --git a/spec/f_http_client/processor/exception_spec.rb b/spec/f_http_client/processor/exception_spec.rb index 0982374..787bf88 100644 --- a/spec/f_http_client/processor/exception_spec.rb +++ b/spec/f_http_client/processor/exception_spec.rb @@ -70,6 +70,19 @@ end end + context 'when the connection could not happen' do + let(:error) { SocketError.new('Failed to open TCP connection to...') } + + it 'logs the request' do + exception_processor + expect(FHTTPClient::Log).to have_received(:call) + end + + it 'fails with connection refused error' do + expect(exception_processor).to have_failed_with(:connection_error, :exception).and_error(error) + end + end + context 'when the connection gets a timeout' do let(:error) { Net::ReadTimeout.new('a timeout happened') }