diff --git a/lib/fog/dns/rackspace.rb b/lib/fog/dns/rackspace.rb index 2a6adadfb..4257f5a2e 100644 --- a/lib/fog/dns/rackspace.rb +++ b/lib/fog/dns/rackspace.rb @@ -45,7 +45,8 @@ module Fog response = @connection.request(params.merge!({ :path => "#{@path}/#{params[:path]}" })) - #TODO - Going to add rescues for the different expected errors + rescue Excon::Errors::BadRequest => error + raise Fog::Rackspace::Errors::BadRequest.slurp error end unless response.body.empty? response.body = MultiJson.decode(response.body) diff --git a/lib/fog/dns/requests/rackspace/list_domains.rb b/lib/fog/dns/requests/rackspace/list_domains.rb index 03ab17b6d..4af2e09c6 100644 --- a/lib/fog/dns/requests/rackspace/list_domains.rb +++ b/lib/fog/dns/requests/rackspace/list_domains.rb @@ -3,10 +3,16 @@ module Fog class Rackspace class Real def list_domains(options={}) + + path = 'domains' + if !options.empty? + path = path + '?' + options.collect {|k,v| "#{k}=#{v}" }.join('&') + end + request( :expects => 200, :method => 'GET', - :path => 'domains' + :path => path ) end end diff --git a/lib/fog/providers/rackspace.rb b/lib/fog/providers/rackspace.rb index 1f23771ab..e2965a3cb 100644 --- a/lib/fog/providers/rackspace.rb +++ b/lib/fog/providers/rackspace.rb @@ -2,9 +2,43 @@ require 'fog/core' module Fog module Rackspace - extend Fog::Provider + module Errors + class ServiceError < Fog::Errors::Error + attr_reader :response_data + + def self.slurp(error) + if error.response.body.empty? + data = nil + message = nil + else + data = MultiJson.decode(error.response.body) + message = data['message'] + end + + new_error = super(error, message) + new_error.instance_variable_set(:@response_data, data) + new_error + end + end + + class InternalServerError < ServiceError; end + + class BadRequest < ServiceError + #TODO - Need to find a bette way to print out these validation errors when they are thrown + attr_reader :validation_errors + + def self.slurp(error) + new_error = super(error) + unless new_error.response_data.nil? + new_error.instance_variable_set(:@validation_errors, new_error.response_data['validationErrors']) + end + new_error + end + end + end + service(:cdn, 'cdn/rackspace') service(:compute, 'compute/rackspace') service(:storage, 'storage/rackspace') @@ -33,6 +67,5 @@ module Fog !['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key) end end - end end diff --git a/lib/fog/rackspace/load_balancers.rb b/lib/fog/rackspace/load_balancers.rb index 264ec68cd..7c6144782 100644 --- a/lib/fog/rackspace/load_balancers.rb +++ b/lib/fog/rackspace/load_balancers.rb @@ -1,39 +1,12 @@ + module Fog module Rackspace class LoadBalancers < Fog::Service - class ServiceError < Fog::Errors::Error - attr_reader :response_data - - def self.slurp(error) - if error.response.body.empty? - data = nil - message = nil - else - data = MultiJson.decode(error.response.body) - message = data['message'] - end - - new_error = super(error, message) - new_error.instance_variable_set(:@response_data, data) - new_error - end - end - - class InternalServerError < ServiceError; end - - class BadRequest < ServiceError - #TODO - Need to find a bette way to print out these validation errors when they are thrown - attr_reader :validation_errors - - def self.slurp(error) - new_error = super(error) - unless new_error.response_data.nil? - new_error.instance_variable_set(:@validation_errors, new_error.response_data['validationErrors']) - end - new_error - end - end + #These references exist for backwards compatibility + class ServiceError < Fog::Rackspace::Errors::ServiceError; end + class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end + class BadRequest < Fog::Rackspace::Errors::BadRequest; end DFW_ENDPOINT = 'https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/' ORD_ENDPOINT = 'https://ord.loadbalancers.api.rackspacecloud.com/v1.0/' diff --git a/tests/dns/requests/rackspace/dns_tests.rb b/tests/dns/requests/rackspace/dns_tests.rb index 280b3aae5..c7a207036 100644 --- a/tests/dns/requests/rackspace/dns_tests.rb +++ b/tests/dns/requests/rackspace/dns_tests.rb @@ -29,8 +29,15 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do tests('list_domains').formats(LIST_DOMAIN_FORMAT) do @service.list_domains.body end + + tests('list_domains :limit => 5, :offset => 10, :domain => "hartsock" --> All possible attributes').formats(LIST_DOMAIN_FORMAT) do + @service.list_domains(:limit => 5, :offset => 10, :domain => 'hartsock').body + end end tests( 'failure') do + tests('list_domains :limit => 5, :offset => 8').raises(Fog::Rackspace::Errors::BadRequest) do + @service.list_domains :limit => 5, :offset => 8 + end end end