lib/frenchy/client.rb in frenchy-0.2.9 vs lib/frenchy/client.rb in frenchy-0.3.0
- old
+ new
@@ -12,10 +12,11 @@
@name = name.to_s
@host = options.fetch("host") { "http://127.0.0.1:8080" }
@timeout = options.fetch("timeout") { 30 }
@retries = options.fetch("retries") { 0 }
@backoff_delay = options.fetch("backoff_delay") { 1.0 }
+ @headers = options.fetch("headers") { {} }
end
# Issue a get request with the given path and query parameters. Get
# requests can be retried.
def get(path, params)
@@ -48,11 +49,11 @@
uri = URI(@host)
body = nil
headers = {
"User-Agent" => "Frenchy/#{Frenchy::VERSION}",
"Accept" => "application/json",
- }
+ }.merge(@headers)
# Set the URI path
uri.path = path
# Set request parameters
@@ -106,10 +107,10 @@
raise Frenchy::InvalidResponse.new(ex, reqinfo, resp)
end
when 404
# Explicitly handle not found errors
raise Frenchy::NotFound.new(nil, reqinfo, resp)
- when 503
+ when 503, 504
# Explicitly handle temporarily unavailable errors
raise Frenchy::TemporarilyUnavailable.new(nil, reqinfo, resp)
else
# All other responses are treated as a server error
raise Frenchy::ServiceUnavailable.new(nil, reqinfo, resp)