From 0d70823bd45199e74f7e3776b4b46017b85aafcf Mon Sep 17 00:00:00 2001 From: izwick-schachter Date: Thu, 14 Dec 2017 17:24:56 -0500 Subject: [PATCH] Added retry on timeout --- lib/se/api.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/se/api.rb b/lib/se/api.rb index 463f64f..4492e73 100644 --- a/lib/se/api.rb +++ b/lib/se/api.rb @@ -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))