Skip to content

Commit

Permalink
Added retry on timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahzs committed Dec 14, 2017
1 parent 78d3dc3 commit 0d70823
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/se/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ def json(uri, **params)
end
params = @params.merge(params).merge({key: @key}).map { |k,v| "#{k}=#{v}" }.join('&')
puts "Posting to https://api.stackexchange.com/#{API_VERSION}/#{uri}?#{params}"
resp_raw = Net::HTTP.get_response(URI("https://api.stackexchange.com/#{API_VERSION}/#{uri}?#{params}")).body
begin
resp_raw = Net::HTTP.get_response(URI("https://api.stackexchange.com/#{API_VERSION}/#{uri}?#{params}")).body
rescue Net::OpenTimeout
puts "Got timeout on API request. Retrying..."
retry
end
@logger_raw.info "https://api.stackexchange.com/#{API_VERSION}/#{uri}?#{params} => #{resp_raw}"
resp = JSON.parse(resp_raw)
@backoff = DateTime.now + (resp["backoff"].to_i/(24*60*60))
Expand Down

0 comments on commit 0d70823

Please sign in to comment.