diff --git a/lib/google/apis/core/http_command.rb b/lib/google/apis/core/http_command.rb index 171642d07..5be15fe21 100644 --- a/lib/google/apis/core/http_command.rb +++ b/lib/google/apis/core/http_command.rb @@ -271,6 +271,7 @@ module Google if err.is_a?(HTTPClient::BadResponseError) begin res = err.res + raise Google::Apis::TransmissionError.new(err) if res.nil? check_status(res.status.to_i, res.header, res.body) rescue Google::Apis::Error => e err = e diff --git a/spec/google/apis/core/http_command_spec.rb b/spec/google/apis/core/http_command_spec.rb index 6f8bdbdef..dc4967898 100644 --- a/spec/google/apis/core/http_command_spec.rb +++ b/spec/google/apis/core/http_command_spec.rb @@ -197,6 +197,32 @@ RSpec.describe Google::Apis::Core::HttpCommand do end end + context('with unknown errors') do + let(:command) do + Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals') + end + + before(:example) do + stub_request(:get, 'https://www.googleapis.com/zoo/animals') + .to_raise(HTTPClient::BadResponseError) # empty error, no res value + end + + it 'should raise transmission error' do + command.options.retries = 1 + + err = nil + begin + command.execute(client) + rescue Google::Apis::Error => e + err = e + end + + expect(err).to be_a(Google::Apis::TransmissionError) + expect(err.cause).to be_a(HTTPClient::BadResponseError) + expect(err.cause.res).to be_nil # no res value + end + end + context('with options') do let(:command) do command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')