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:
parent
4fb0522361
commit
1173a7ef84
9 changed files with 48 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
|||
require File.join(File.dirname(__FILE__), 'core')
|
||||
require 'fog/rackspace/mock_data'
|
||||
require 'fog/rackspace/service'
|
||||
require 'fog/rackspace/errors'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
|
@ -25,21 +26,24 @@ module Fog
|
|||
if error.response
|
||||
status_code = error.response.status
|
||||
unless error.response.body.empty?
|
||||
data = Fog::JSON.decode(error.response.body)
|
||||
message = data.values.first ? data.values.first['message'] : data['message']
|
||||
begin
|
||||
data = Fog::JSON.decode(error.response.body)
|
||||
message = data.values.first ? data.values.first['message'] : data['message']
|
||||
rescue Fog::JSON::LoadError => e
|
||||
data = error.response.body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
new_error = super(error, message)
|
||||
new_error.instance_variable_set(:@response_data, data)
|
||||
new_error.instance_variable_set(:@status_code, status_code)
|
||||
new_error.instance_variable_set(:@status_code, status_code)
|
||||
new_error
|
||||
end
|
||||
end
|
||||
|
||||
class InternalServerError < ServiceError; end
|
||||
class Conflict < ServiceError; end
|
||||
class NotFound < ServiceError; end
|
||||
class ServiceUnavailable < ServiceError; end
|
||||
|
||||
class BadRequest < ServiceError
|
||||
|
|
|
@ -3,6 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rackspace'))
|
|||
module Fog
|
||||
module Rackspace
|
||||
class BlockStorage < Fog::Service
|
||||
include Fog::Rackspace::Errors
|
||||
|
||||
class IdentifierTaken < Fog::Errors::Error; end
|
||||
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
|
||||
|
@ -98,7 +99,7 @@ module Fog
|
|||
:path => "#{endpoint_uri.path}/#{params[:path]}"
|
||||
}))
|
||||
rescue Excon::Errors::NotFound => error
|
||||
raise NotFound.slurp error
|
||||
raise NotFound.slurp(error, region)
|
||||
rescue Excon::Errors::BadRequest => error
|
||||
raise BadRequest.slurp error
|
||||
rescue Excon::Errors::InternalServerError => error
|
||||
|
|
|
@ -4,7 +4,6 @@ require 'fog/cdn'
|
|||
module Fog
|
||||
module CDN
|
||||
class Rackspace < Fog::Service
|
||||
|
||||
requires :rackspace_api_key, :rackspace_username
|
||||
recognizes :rackspace_auth_url, :persistent, :rackspace_cdn_ssl, :rackspace_region, :rackspace_cdn_url
|
||||
|
||||
|
@ -167,7 +166,7 @@ module Fog
|
|||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::Storage::Rackspace::NotFound.slurp(error)
|
||||
Fog::Storage::Rackspace::NotFound.slurp(error, region)
|
||||
else
|
||||
error
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ require 'fog/compute'
|
|||
module Fog
|
||||
module Compute
|
||||
class Rackspace < Fog::Service
|
||||
include Fog::Rackspace::Errors
|
||||
|
||||
requires :rackspace_api_key, :rackspace_username
|
||||
recognizes :rackspace_auth_url, :rackspace_servicenet, :persistent
|
||||
|
@ -223,7 +224,7 @@ module Fog
|
|||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::Compute::Rackspace::NotFound.slurp(error)
|
||||
NotFound.slurp(error, region)
|
||||
else
|
||||
error
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ require 'fog/compute'
|
|||
module Fog
|
||||
module Compute
|
||||
class RackspaceV2 < Fog::Service
|
||||
include Fog::Rackspace::Errors
|
||||
|
||||
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
|
||||
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
|
||||
|
@ -148,7 +149,7 @@ module Fog
|
|||
:path => "#{endpoint_uri.path}/#{params[:path]}"
|
||||
}))
|
||||
rescue Excon::Errors::NotFound => error
|
||||
raise NotFound.slurp error
|
||||
raise NotFound.slurp(error, region)
|
||||
rescue Excon::Errors::BadRequest => error
|
||||
raise BadRequest.slurp error
|
||||
rescue Excon::Errors::InternalServerError => error
|
||||
|
|
|
@ -3,6 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rackspace'))
|
|||
module Fog
|
||||
module Rackspace
|
||||
class Databases < Fog::Service
|
||||
include Fog::Rackspace::Errors
|
||||
|
||||
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
|
||||
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
|
||||
|
@ -96,7 +97,7 @@ module Fog
|
|||
:path => "#{endpoint_uri.path}/#{params[:path]}"
|
||||
}))
|
||||
rescue Excon::Errors::NotFound => error
|
||||
raise NotFound.slurp error
|
||||
raise NotFound.slurp(error, region)
|
||||
rescue Excon::Errors::BadRequest => error
|
||||
raise BadRequest.slurp error
|
||||
rescue Excon::Errors::InternalServerError => error
|
||||
|
|
27
lib/fog/rackspace/errors.rb
Normal file
27
lib/fog/rackspace/errors.rb
Normal 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
|
|
@ -3,6 +3,7 @@ require 'fog/rackspace'
|
|||
module Fog
|
||||
module Rackspace
|
||||
class LoadBalancers < Fog::Service
|
||||
include Fog::Rackspace::Errors
|
||||
|
||||
#These references exist for backwards compatibility
|
||||
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
|
||||
|
@ -131,7 +132,7 @@ module Fog
|
|||
:path => "#{endpoint_uri.path}/#{params[:path]}"
|
||||
}))
|
||||
rescue Excon::Errors::NotFound => error
|
||||
raise NotFound.slurp error
|
||||
raise NotFound.slurp(error, region)
|
||||
rescue Excon::Errors::BadRequest => error
|
||||
raise BadRequest.slurp error
|
||||
rescue Excon::Errors::InternalServerError => error
|
||||
|
|
|
@ -4,6 +4,7 @@ require 'fog/storage'
|
|||
module Fog
|
||||
module Storage
|
||||
class Rackspace < Fog::Service
|
||||
include Fog::Rackspace::Errors
|
||||
|
||||
requires :rackspace_api_key, :rackspace_username
|
||||
recognizes :rackspace_auth_url, :rackspace_servicenet, :rackspace_cdn_ssl, :persistent, :rackspace_region
|
||||
|
@ -155,7 +156,7 @@ module Fog
|
|||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::Storage::Rackspace::NotFound.slurp(error)
|
||||
NotFound.slurp(error, region)
|
||||
else
|
||||
error
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue