Handle bad response errors without response object (#765)

We have received word that a bad proxy setting can cause this behavior.

[fixes #764]
This commit is contained in:
Mike Moore 2019-02-14 14:14:34 -07:00 committed by GitHub
parent 06a01959cf
commit 6e90789b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -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

View File

@ -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')