Skip to content

Commit

Permalink
Merge pull request #10 from railsmachine/rails-machine-raise-exceptio…
Browse files Browse the repository at this point in the history
…n-instead-of-exiting-on-error

No longer exit on an unknown API error.
  • Loading branch information
isaacchiang committed Sep 17, 2013
2 parents 4f7dc34 + 3e236a1 commit 13511e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bin/cloudstack_ruby_client
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ begin
end
rescue ArgumentError => e
puts "#{e.to_s}"
rescue CloudstackRubyClient::RequestError => e
puts "Error #{e.response.code}: #{JSON.pretty_generate(e.json)}"
rescue RuntimeError => e
puts "Oops! something bad happened. Please try again"
rescue
Expand Down
15 changes: 11 additions & 4 deletions lib/cloudstack_ruby_client/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
class CloudstackRubyClient::RequestError < RuntimeError
attr_reader :response, :json

def initialize(response, json)
@response = response
@json = json
end
end

class CloudstackRubyClient::Client < CloudstackRubyClient::BaseClient

@@API_LIST = []
Expand Down Expand Up @@ -51,10 +60,8 @@ def auth_request(params, command)
end

raise RuntimeError, json['errorresponse']['errortext'] if response.code == "432"

puts 'Error ' + response.code + ':'
puts JSON.pretty_generate(json)
exit 1

raise CloudstackRubyClient::RequestError.new(response, json)
end

json[resp_title]
Expand Down
4 changes: 1 addition & 3 deletions lib/cloudstack_ruby_client/client_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ def #{arg}(args={});
raise RuntimeError, json['errorresponse']['errortext'] if response.code == "432"
puts 'Error ' + response.code + ':'
puts JSON.pretty_generate(json)
exit 1
raise CloudstackRubyClient::RequestError.new(response, json)
end
json[resp_title]
Expand Down

0 comments on commit 13511e5

Please sign in to comment.