lib/onering/api.rb in onering-client-0.0.22 vs lib/onering/api.rb in onering-client-0.0.23
- old
+ new
@@ -74,15 +74,14 @@
uri = Addressable::URI.parse("#{@_uri.to_s}/#{endpoint}")
uri.query_values = options[:fields] if options[:fields]
raise Errors::NotConnected unless @_http
- #STDERR.puts "DEBUG: Request #{options[:method].to_s.upcase} #{uri.normalize.to_s}"
-
case options[:method]
when :post
request = Net::HTTP::Post.new(uri.request_uri)
+ request['Content-Type'] = 'application/json'
request.body = options[:data].to_json if options[:data]
when :delete
request = Net::HTTP::Delete.new(uri.request_uri)
@@ -92,10 +91,10 @@
end
response = @_http.request(request)
if response.code.to_i >= 400
- rv = JSON.load(response.body) unless response.body.empty?
+ rv = (JSON.load(response.body) rescue {}) unless response.body.empty?
if rv['errors']
msg = "#{rv['errors']['type']}: #{rv['errors']['message']}"
end