1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[rackspace] updated NotFound exceptions to include region when available.

This commit is contained in:
Kyle Rames 2013-04-15 09:31:13 -05:00
parent 4fb0522361
commit 1173a7ef84
9 changed files with 48 additions and 12 deletions

View file

@ -1,6 +1,7 @@
require File.join(File.dirname(__FILE__), 'core') require File.join(File.dirname(__FILE__), 'core')
require 'fog/rackspace/mock_data' require 'fog/rackspace/mock_data'
require 'fog/rackspace/service' require 'fog/rackspace/service'
require 'fog/rackspace/errors'
module Fog module Fog
module Rackspace module Rackspace
@ -25,8 +26,12 @@ module Fog
if error.response if error.response
status_code = error.response.status status_code = error.response.status
unless error.response.body.empty? unless error.response.body.empty?
begin
data = Fog::JSON.decode(error.response.body) data = Fog::JSON.decode(error.response.body)
message = data.values.first ? data.values.first['message'] : data['message'] message = data.values.first ? data.values.first['message'] : data['message']
rescue Fog::JSON::LoadError => e
data = error.response.body
end
end end
end end
@ -39,7 +44,6 @@ module Fog
class InternalServerError < ServiceError; end class InternalServerError < ServiceError; end
class Conflict < ServiceError; end class Conflict < ServiceError; end
class NotFound < ServiceError; end
class ServiceUnavailable < ServiceError; end class ServiceUnavailable < ServiceError; end
class BadRequest < ServiceError class BadRequest < ServiceError

View file

@ -3,6 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rackspace'))
module Fog module Fog
module Rackspace module Rackspace
class BlockStorage < Fog::Service class BlockStorage < Fog::Service
include Fog::Rackspace::Errors
class IdentifierTaken < Fog::Errors::Error; end class IdentifierTaken < Fog::Errors::Error; end
class ServiceError < Fog::Rackspace::Errors::ServiceError; end class ServiceError < Fog::Rackspace::Errors::ServiceError; end
@ -98,7 +99,7 @@ module Fog
:path => "#{endpoint_uri.path}/#{params[:path]}" :path => "#{endpoint_uri.path}/#{params[:path]}"
})) }))
rescue Excon::Errors::NotFound => error rescue Excon::Errors::NotFound => error
raise NotFound.slurp error raise NotFound.slurp(error, region)
rescue Excon::Errors::BadRequest => error rescue Excon::Errors::BadRequest => error
raise BadRequest.slurp error raise BadRequest.slurp error
rescue Excon::Errors::InternalServerError => error rescue Excon::Errors::InternalServerError => error

View file

@ -4,7 +4,6 @@ require 'fog/cdn'
module Fog module Fog
module CDN module CDN
class Rackspace < Fog::Service class Rackspace < Fog::Service
requires :rackspace_api_key, :rackspace_username requires :rackspace_api_key, :rackspace_username
recognizes :rackspace_auth_url, :persistent, :rackspace_cdn_ssl, :rackspace_region, :rackspace_cdn_url recognizes :rackspace_auth_url, :persistent, :rackspace_cdn_ssl, :rackspace_region, :rackspace_cdn_url
@ -167,7 +166,7 @@ module Fog
rescue Excon::Errors::HTTPStatusError => error rescue Excon::Errors::HTTPStatusError => error
raise case error raise case error
when Excon::Errors::NotFound when Excon::Errors::NotFound
Fog::Storage::Rackspace::NotFound.slurp(error) Fog::Storage::Rackspace::NotFound.slurp(error, region)
else else
error error
end end

View file

@ -4,6 +4,7 @@ require 'fog/compute'
module Fog module Fog
module Compute module Compute
class Rackspace < Fog::Service class Rackspace < Fog::Service
include Fog::Rackspace::Errors
requires :rackspace_api_key, :rackspace_username requires :rackspace_api_key, :rackspace_username
recognizes :rackspace_auth_url, :rackspace_servicenet, :persistent recognizes :rackspace_auth_url, :rackspace_servicenet, :persistent
@ -223,7 +224,7 @@ module Fog
rescue Excon::Errors::HTTPStatusError => error rescue Excon::Errors::HTTPStatusError => error
raise case error raise case error
when Excon::Errors::NotFound when Excon::Errors::NotFound
Fog::Compute::Rackspace::NotFound.slurp(error) NotFound.slurp(error, region)
else else
error error
end end

View file

@ -3,6 +3,7 @@ require 'fog/compute'
module Fog module Fog
module Compute module Compute
class RackspaceV2 < Fog::Service class RackspaceV2 < Fog::Service
include Fog::Rackspace::Errors
class ServiceError < Fog::Rackspace::Errors::ServiceError; end class ServiceError < Fog::Rackspace::Errors::ServiceError; end
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
@ -148,7 +149,7 @@ module Fog
:path => "#{endpoint_uri.path}/#{params[:path]}" :path => "#{endpoint_uri.path}/#{params[:path]}"
})) }))
rescue Excon::Errors::NotFound => error rescue Excon::Errors::NotFound => error
raise NotFound.slurp error raise NotFound.slurp(error, region)
rescue Excon::Errors::BadRequest => error rescue Excon::Errors::BadRequest => error
raise BadRequest.slurp error raise BadRequest.slurp error
rescue Excon::Errors::InternalServerError => error rescue Excon::Errors::InternalServerError => error

View file

@ -3,6 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rackspace'))
module Fog module Fog
module Rackspace module Rackspace
class Databases < Fog::Service class Databases < Fog::Service
include Fog::Rackspace::Errors
class ServiceError < Fog::Rackspace::Errors::ServiceError; end class ServiceError < Fog::Rackspace::Errors::ServiceError; end
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
@ -96,7 +97,7 @@ module Fog
:path => "#{endpoint_uri.path}/#{params[:path]}" :path => "#{endpoint_uri.path}/#{params[:path]}"
})) }))
rescue Excon::Errors::NotFound => error rescue Excon::Errors::NotFound => error
raise NotFound.slurp error raise NotFound.slurp(error, region)
rescue Excon::Errors::BadRequest => error rescue Excon::Errors::BadRequest => error
raise BadRequest.slurp error raise BadRequest.slurp error
rescue Excon::Errors::InternalServerError => error rescue Excon::Errors::InternalServerError => error

View file

@ -0,0 +1,27 @@
module Fog
module Rackspace
module Errors
def self.included(mod)
mod.class_eval <<-'EOS', __FILE__, __LINE__
class NotFound < Fog::Service::NotFound
attr_reader :region, :status_code
def to_s
status = status_code ? "[HTTP #{status_code}] " : ""
message = region ? "resource not found in #{region} region" : super
"#{status}#{message}"
end
def self.slurp(error, region=nil)
exception = NotFound.new
exception.instance_variable_set(:@region, region)
exception.instance_variable_set(:@status_code, error.response.status) rescue nil
exception
end
end
EOS
end
end
end
end

View file

@ -3,6 +3,7 @@ require 'fog/rackspace'
module Fog module Fog
module Rackspace module Rackspace
class LoadBalancers < Fog::Service class LoadBalancers < Fog::Service
include Fog::Rackspace::Errors
#These references exist for backwards compatibility #These references exist for backwards compatibility
class ServiceError < Fog::Rackspace::Errors::ServiceError; end class ServiceError < Fog::Rackspace::Errors::ServiceError; end
@ -131,7 +132,7 @@ module Fog
:path => "#{endpoint_uri.path}/#{params[:path]}" :path => "#{endpoint_uri.path}/#{params[:path]}"
})) }))
rescue Excon::Errors::NotFound => error rescue Excon::Errors::NotFound => error
raise NotFound.slurp error raise NotFound.slurp(error, region)
rescue Excon::Errors::BadRequest => error rescue Excon::Errors::BadRequest => error
raise BadRequest.slurp error raise BadRequest.slurp error
rescue Excon::Errors::InternalServerError => error rescue Excon::Errors::InternalServerError => error

View file

@ -4,6 +4,7 @@ require 'fog/storage'
module Fog module Fog
module Storage module Storage
class Rackspace < Fog::Service class Rackspace < Fog::Service
include Fog::Rackspace::Errors
requires :rackspace_api_key, :rackspace_username requires :rackspace_api_key, :rackspace_username
recognizes :rackspace_auth_url, :rackspace_servicenet, :rackspace_cdn_ssl, :persistent, :rackspace_region recognizes :rackspace_auth_url, :rackspace_servicenet, :rackspace_cdn_ssl, :persistent, :rackspace_region
@ -155,7 +156,7 @@ module Fog
rescue Excon::Errors::HTTPStatusError => error rescue Excon::Errors::HTTPStatusError => error
raise case error raise case error
when Excon::Errors::NotFound when Excon::Errors::NotFound
Fog::Storage::Rackspace::NotFound.slurp(error) NotFound.slurp(error, region)
else else
error error
end end