lib/cloudstack_client/client.rb in cloudstack_client-0.3.6 vs lib/cloudstack_client/client.rb in cloudstack_client-0.4.0
- old
+ new
@@ -66,23 +66,26 @@
puts "Error connecting to API:"
puts "#{@api_url} is not reachable"
exit 1
end
- if !response.is_a?(Net::HTTPOK)
+ if response.is_a?(Net::HTTPOK)
+ begin
+ json = JSON.parse(response.body)
+ json[params['command'].downcase + 'response']
+ rescue JSON::ParserError
+ puts "Error parsing response from server."
+ exit 1
+ end
+ elsif response.is_a?(Net::HTTPUnauthorized)
puts "Error #{response.code}: #{response.message}"
+ exit 2
+ else
+ puts "Error #{response.code}: #{response.message}"
puts JSON.pretty_generate(JSON.parse(response.body))
puts "URL: #{url}"
exit 1
end
-
- begin
- json = JSON.parse(response.body)
- rescue JSON::ParserError
- puts "Error parsing response from server."
- exit 1
- end
- json[params['command'].downcase + 'response']
end
##
# Sends an asynchronous request and waits for the response.
#
\ No newline at end of file