lib/berkshelf/api_client/connection.rb in berkshelf-api-client-1.1.0 vs lib/berkshelf/api_client/connection.rb in berkshelf-api-client-1.1.1
- old
+ new
@@ -1,8 +1,10 @@
require 'faraday'
module Berkshelf::APIClient
+ require_relative 'errors'
+
class Connection < Faraday::Connection
# @return [String]
attr_reader :url
# @return [Integer]
@@ -34,11 +36,14 @@
b.response :parse_json
b.response :gzip
b.request :retry,
max: self.retries,
interval: self.retry_interval,
- exceptions: [ Faraday::Error::TimeoutError, Errno::ETIMEDOUT ]
+ exceptions: [
+ Faraday::Error::TimeoutError,
+ Errno::ETIMEDOUT
+ ]
b.adapter :net_http
end
super(self.url, options)
@@ -60,16 +65,18 @@
response.body.each do |name, versions|
versions.each { |version, attributes| cookbooks << RemoteCookbook.new(name, version, attributes) }
end
end
when 404
- raise APIClient::ServiceNotFound, "service not found at: #{url}"
+ raise ServiceNotFound, "service not found at: #{url}"
when 500..504
- raise APIClient::ServiceUnavaiable, "service unavailable at: #{url}"
+ raise ServiceUnavaiable, "service unavailable at: #{url}"
else
- raise APIClient::BadResponse, "bad response #{response.inspect}"
+ raise BadResponse, "bad response #{response.inspect}"
end
rescue Faraday::Error::TimeoutError, Errno::ETIMEDOUT
- raise APIClient::TimeoutError, "Unable to connect to: #{url}"
+ raise TimeoutError, "Unable to connect to: #{url}"
+ rescue Faraday::Error::ConnectionFailed => ex
+ raise ServiceUnavaiable, ex
end
end
end