2013-04-15 10:31:13 -04:00
|
|
|
module Fog
|
|
|
|
module Rackspace
|
|
|
|
module Errors
|
|
|
|
|
|
|
|
def self.included(mod)
|
|
|
|
mod.class_eval <<-'EOS', __FILE__, __LINE__
|
|
|
|
class NotFound < Fog::Service::NotFound
|
2013-08-01 15:31:51 -04:00
|
|
|
attr_reader :region, :status_code, :transaction_id
|
2013-04-15 10:31:13 -04:00
|
|
|
|
|
|
|
def to_s
|
2013-08-01 15:31:51 -04:00
|
|
|
status = status_code ? "HTTP #{status_code}" : "HTTP <Unknown>"
|
2013-04-15 10:31:13 -04:00
|
|
|
message = region ? "resource not found in #{region} region" : super
|
2013-08-01 15:31:51 -04:00
|
|
|
"[#{status} | #{transaction_id}] #{message}"
|
2013-04-15 10:31:13 -04:00
|
|
|
end
|
|
|
|
|
2013-08-01 15:31:51 -04:00
|
|
|
def self.slurp(error, service=nil)
|
2013-04-15 10:31:13 -04:00
|
|
|
exception = NotFound.new
|
2013-08-01 15:31:51 -04:00
|
|
|
exception.instance_variable_set(:@region, service.region) if service && service.respond_to?(:region)
|
2013-04-15 10:31:13 -04:00
|
|
|
exception.instance_variable_set(:@status_code, error.response.status) rescue nil
|
2013-08-01 15:31:51 -04:00
|
|
|
exception.set_transaction_id(error, service)
|
2013-04-15 10:31:13 -04:00
|
|
|
exception
|
|
|
|
end
|
2013-08-01 15:31:51 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-04-15 10:31:13 -04:00
|
|
|
end
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|