From 07ca6e8ca0854808c34a1779dc23c4645d1fd61f Mon Sep 17 00:00:00 2001 From: Steve Bazyl Date: Thu, 25 Feb 2016 13:30:27 -0800 Subject: [PATCH] Handle SocketError. #359 --- lib/google/apis/core/http_command.rb | 2 +- spec/google/apis/core/http_command_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/google/apis/core/http_command.rb b/lib/google/apis/core/http_command.rb index aad907d26..bcea5c53a 100644 --- a/lib/google/apis/core/http_command.rb +++ b/lib/google/apis/core/http_command.rb @@ -251,7 +251,7 @@ module Google # @raise [StandardError] if no block def error(err, rethrow: false, &block) logger.debug { sprintf('Error - %s', PP.pp(err, '')) } - err = Google::Apis::TransmissionError.new(err) if err.is_a?(Hurley::ClientError) + err = Google::Apis::TransmissionError.new(err) if err.is_a?(Hurley::ClientError) || err.is_a?(SocketError) block.call(nil, err) if block_given? fail err if rethrow || block.nil? end diff --git a/spec/google/apis/core/http_command_spec.rb b/spec/google/apis/core/http_command_spec.rb index d9c98df66..e9e9ead39 100644 --- a/spec/google/apis/core/http_command_spec.rb +++ b/spec/google/apis/core/http_command_spec.rb @@ -294,4 +294,10 @@ RSpec.describe Google::Apis::Core::HttpCommand do command.execute(client) end + it 'should raise transmission error instead of socket error' do + stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_raise(SocketError) + command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals') + command.options.retries = 0 + expect { command.execute(client) }.to raise_error(Google::Apis::TransmissionError) + end end