Permalink
Browse files

Retry on SocketErrors.

  • Loading branch information...
1 parent 2ed2dcf commit f530ba6ff5fb1764b78a757545abe1da9931ee77 @watsonian committed Apr 1, 2012
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/zapi/base.rb
View
14 lib/zapi/base.rb
@@ -17,8 +17,12 @@ def self.get(path, params={})
"Content-Type" => "application/json"
}
}
- options.merge(:query => {:query => query_for(params)}) if params.any?
- response = api.get(options)
+ options.merge!(:query => {:query => query_for(params)}) if params.any?
+ begin
+ response = api.get(options)
+ rescue Excon::Errors::SocketError
+ retry
+ end
objectify(JSON.parse(response.body, :symbolize_keys => true))
end
@@ -28,7 +32,11 @@ def self.find(query)
end
def self.all
- @@cache ||= get("/#{name}.json")
+ begin
+ @@cache ||= get("/#{name}.json")
+ rescue Excon::Errors::SocketError
+ retry
+ end
end
private

0 comments on commit f530ba6

Please sign in to comment.