Skip to content

Commit

Permalink
only retry a few times
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmario committed May 6, 2010
1 parent e272d32 commit 5727d32
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/facebook-graphclient.rb
Expand Up @@ -47,12 +47,15 @@ def api action, method, query_params = nil

query_string = '?' + query_params.map { |k,v| "#{k}=#{v}" }.join("&") unless query_params.empty?

tries = 0
begin
raw_response = @session.send(action, GRAPH_URL + method + query_string)
rescue Patron::HostResolutionError
retry
retry if tries < 5
tries += 1
rescue Patron::ConnectionFailed
retry
retry if tries < 5
tries += 1
end

# TODO: Handle photo requests, which return photo data and not JSON
Expand Down Expand Up @@ -80,12 +83,15 @@ def fql query

query_string = '?' + query_params.map { |k,v| "#{k}=#{v}" }.join("&") unless query_params.empty?

tries = 0
begin
raw_response = @session.get("https://api.facebook.com/method/fql.query" + query_string)
rescue Patron::HostResolutionError
retry
retry if tries < 5
tries += 1
rescue Patron::ConnectionFailed
retry
retry if tries < 5
tries += 1
end

response = Yajl::Parser.parse(raw_response.body)
Expand Down

0 comments on commit 5727d32

Please sign in to comment.