Skip to content

Commit

Permalink
Merge pull request #1260 from JackTLi/clear-last-response-on-errors
Browse files Browse the repository at this point in the history
Clear last_response on errors
  • Loading branch information
tarebyte authored May 22, 2020
2 parents 3af5739 + d79667d commit 8342891
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit 8342891

Please sign in to comment.