mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace] updated exceptions to include the service transaction id if available.
This commit is contained in:
parent
84b961e7d7
commit
6a1a2d583c
6 changed files with 56 additions and 24 deletions
|
@ -12,10 +12,11 @@ module Fog
|
|||
|
||||
module Errors
|
||||
class ServiceError < Fog::Errors::Error
|
||||
attr_reader :response_data, :status_code
|
||||
attr_reader :response_data, :status_code, :transaction_id
|
||||
|
||||
def to_s
|
||||
status_code ? "[HTTP #{status_code}] #{super}" : super
|
||||
status = status_code ? "HTTP #{status_code}" : "HTTP <Unknown>"
|
||||
"[#{status} | #{transaction_id}] #{super}"
|
||||
end
|
||||
|
||||
def self.slurp(error)
|
||||
|
@ -40,11 +41,17 @@ module Fog
|
|||
new_error = super(error, message)
|
||||
new_error.instance_variable_set(:@response_data, data)
|
||||
new_error.instance_variable_set(:@status_code, status_code)
|
||||
new_error.set_transaction_id(error, service)
|
||||
new_error
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_transaction_id(error, service)
|
||||
return unless service && service.respond_to?(:request_id_header) && error.response
|
||||
@transaction_id = error.response.headers[service.request_id_header]
|
||||
end
|
||||
|
||||
def self.extract_message(data)
|
||||
if data.is_a?(Hash)
|
||||
message = data.values.first['message'] if data.values.first.is_a?(Hash)
|
||||
|
@ -67,7 +74,9 @@ module Fog
|
|||
unless new_error.response_data.nil? or new_error.response_data['badRequest'].nil?
|
||||
new_error.instance_variable_set(:@validation_errors, new_error.response_data['badRequest']['validationErrors'])
|
||||
end
|
||||
new_error
|
||||
|
||||
new_error.instance_variable_set(:@status_code, status_code)
|
||||
new_error.set_transaction_id(error, service)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -90,13 +90,13 @@ module Fog
|
|||
def request(params, parse_json = true, &block)
|
||||
super(params, parse_json, &block)
|
||||
rescue Excon::Errors::NotFound => error
|
||||
raise NotFound.slurp(error, region)
|
||||
raise NotFound.slurp(error, self)
|
||||
rescue Excon::Errors::BadRequest => error
|
||||
raise BadRequest.slurp error
|
||||
raise BadRequest.slurp(error, self)
|
||||
rescue Excon::Errors::InternalServerError => error
|
||||
raise InternalServerError.slurp error
|
||||
raise InternalServerError.slurp(error, self)
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise ServiceError.slurp error
|
||||
raise ServiceError.slurp(error, self)
|
||||
end
|
||||
|
||||
def authenticate(options={})
|
||||
|
@ -116,6 +116,10 @@ module Fog
|
|||
@rackspace_region
|
||||
end
|
||||
|
||||
def request_id_header
|
||||
"X-Compute-Request-Id"
|
||||
end
|
||||
|
||||
def endpoint_uri(service_endpoint_url=nil)
|
||||
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_block_storage_url)
|
||||
end
|
||||
|
|
|
@ -31,6 +31,10 @@ module Fog
|
|||
@rackspace_region
|
||||
end
|
||||
|
||||
def request_id_header
|
||||
"X-Trans-Id"
|
||||
end
|
||||
|
||||
def endpoint_uri(service_endpoint_url=nil)
|
||||
@uri = super(@rackspace_cdn_url || service_endpoint_url, :rackspace_cdn_url)
|
||||
end
|
||||
|
@ -155,13 +159,13 @@ module Fog
|
|||
def request(params, parse_json = true, &block)
|
||||
super(params, parse_json, &block)
|
||||
rescue Excon::Errors::NotFound => error
|
||||
raise Fog::Storage::Rackspace::NotFound.slurp(error, region)
|
||||
raise Fog::Storage::Rackspace::NotFound.slurp(error, self)
|
||||
rescue Excon::Errors::BadRequest => error
|
||||
raise Fog::Storage::Rackspace::BadRequest.slurp error
|
||||
raise Fog::Storage::Rackspace::BadRequest.slurp(error, self)
|
||||
rescue Excon::Errors::InternalServerError => error
|
||||
raise Fog::Storage::Rackspace::InternalServerError.slurp error
|
||||
raise Fog::Storage::Rackspace::InternalServerError.slurp(error, self)
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise Fog::Storage::Rackspace::ServiceError.slurp error
|
||||
raise Fog::Storage::Rackspace::ServiceError.slurp(error, self)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -149,13 +149,13 @@ module Fog
|
|||
def request(params, parse_json = true, &block)
|
||||
super(params, parse_json, &block)
|
||||
rescue Excon::Errors::NotFound => error
|
||||
raise NotFound.slurp(error, region)
|
||||
raise NotFound.slurp(error, self)
|
||||
rescue Excon::Errors::BadRequest => error
|
||||
raise BadRequest.slurp error
|
||||
raise BadRequest.slurp(error, self)
|
||||
rescue Excon::Errors::InternalServerError => error
|
||||
raise InternalServerError.slurp error
|
||||
raise InternalServerError.slurp(error, self)
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise ServiceError.slurp error
|
||||
raise ServiceError.slurp(error, self)
|
||||
end
|
||||
|
||||
def authenticate(options={})
|
||||
|
@ -171,6 +171,10 @@ module Fog
|
|||
:cloudServersOpenStack
|
||||
end
|
||||
|
||||
def request_id_header
|
||||
"X-Compute-Request-Id"
|
||||
end
|
||||
|
||||
def region
|
||||
@rackspace_region
|
||||
end
|
||||
|
|
|
@ -5,20 +5,27 @@ module Fog
|
|||
def self.included(mod)
|
||||
mod.class_eval <<-'EOS', __FILE__, __LINE__
|
||||
class NotFound < Fog::Service::NotFound
|
||||
attr_reader :region, :status_code
|
||||
attr_reader :region, :status_code, :transaction_id
|
||||
|
||||
def to_s
|
||||
status = status_code ? "[HTTP #{status_code}] " : ""
|
||||
status = status_code ? "HTTP #{status_code}" : "HTTP <Unknown>"
|
||||
message = region ? "resource not found in #{region} region" : super
|
||||
"#{status}#{message}"
|
||||
"[#{status} | #{transaction_id}] #{message}"
|
||||
end
|
||||
|
||||
def self.slurp(error, region=nil)
|
||||
def self.slurp(error, service=nil)
|
||||
exception = NotFound.new
|
||||
exception.instance_variable_set(:@region, region)
|
||||
exception.instance_variable_set(:@region, service.region) if service && service.respond_to?(:region)
|
||||
exception.instance_variable_set(:@status_code, error.response.status) rescue nil
|
||||
exception.set_transaction_id(error, service)
|
||||
exception
|
||||
end
|
||||
|
||||
def set_transaction_id(error, service)
|
||||
return unless service && service.respond_to?(:request_id_header) && error.response
|
||||
@transaction_id = error.response.headers[service.request_id_header]
|
||||
end
|
||||
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
|
|
@ -145,13 +145,13 @@ module Fog
|
|||
def request(params, parse_json = true, &block)
|
||||
super(params, parse_json, &block)
|
||||
rescue Excon::Errors::NotFound => error
|
||||
raise NotFound.slurp(error, region)
|
||||
raise NotFound.slurp(error, self)
|
||||
rescue Excon::Errors::BadRequest => error
|
||||
raise BadRequest.slurp error
|
||||
raise BadRequest.slurp(error, self)
|
||||
rescue Excon::Errors::InternalServerError => error
|
||||
raise InternalServerError.slurp error
|
||||
raise InternalServerError.slurp(error, self)
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise ServiceError.slurp error
|
||||
raise ServiceError.slurp(error, self)
|
||||
end
|
||||
|
||||
def service_net?
|
||||
|
@ -177,6 +177,10 @@ module Fog
|
|||
:cloudFiles
|
||||
end
|
||||
|
||||
def request_id_header
|
||||
"X-Trans-Id"
|
||||
end
|
||||
|
||||
def region
|
||||
@rackspace_region
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue