lib/kentaa/api/request.rb in kentaa-api-0.2.1 vs lib/kentaa/api/request.rb in kentaa-api-0.3.0
- old
+ new
@@ -18,20 +18,26 @@
request = Net::HTTP::Get.new(uri)
request["X-Api-Key"] = config.api_key
begin
- response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
+ result = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
http.request(request)
end
# Try to catch some common exceptions Net::HTTP might raise.
rescue Errno::ETIMEDOUT, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH,
IOError, SocketError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::OpenTimeout,
Net::ProtocolError, Net::ReadTimeout, OpenSSL::SSL::SSLError => e
raise Kentaa::Api::Exception, e.message
end
- Kentaa::Api::Response.new(response)
+ response = Kentaa::Api::Response.new(result)
+
+ if response.error?
+ raise Kentaa::Api::RequestError, response
+ end
+
+ response
end
end
end
end