Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear last_response on errors #1260

Merged
merged 2 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/octokit/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def request(method, path, data, options = {})

@last_response = response = agent.call(method, Addressable::URI.parse(path.to_s).normalize.to_s, data, options)
response.data
rescue Octokit::Error => error
@last_response = nil
raise error
end

# Executes the request, checking if it was successful
Expand All @@ -177,7 +180,7 @@ def sawyer_options
conn_opts[:proxy] = @proxy if @proxy
if conn_opts[:ssl].nil?
conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode
else
else
if @connection_options[:ssl][:verify] == false
conn_opts[:ssl] = { :verify_mode => 0}
else
Expand Down
16 changes: 16 additions & 0 deletions spec/octokit/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,22 @@
expect { Octokit.get('/user') }.to raise_error Octokit::ServerError
end

it "resets last_response on errors" do
stub_get('/booya').to_return(:status => 200)
stub_get('/user').to_return \
:status => 509,
:headers => {
:content_type => "application/json",
},
:body => {:message => "Bandwidth exceeded"}.to_json

client = Octokit.client
client.get('/booya')
expect(client.last_response).to_not be_nil
expect { client.get('/user') }.to raise_error Octokit::ServerError
expect(client.last_response).to be_nil
end

it "handles documentation URLs in error messages" do
stub_get('/user').to_return \
:status => 415,
Expand Down