Class: Fog::Rackspace::Errors::ServiceError

Inherits:
Errors::Error
  • Object
show all
Defined in:
lib/fog/rackspace/core.rb

Direct Known Subclasses

Compute::Rackspace::ServiceError, Compute::RackspaceV2::ServiceError, DNS::Rackspace::ServiceError, AutoScale::ServiceError, BlockStorage::ServiceError, Databases::ServiceError, BadRequest, Conflict, InternalServerError, MethodNotAllowed, ServiceUnavailable, LoadBalancers::ServiceError, Monitoring::ServiceError, Queues::ServiceError, Storage::Rackspace::ServiceError

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) response_data (readonly)

Returns the value of attribute response_data



16
17
18
# File 'lib/fog/rackspace/core.rb', line 16

def response_data
  @response_data
end

- (Object) status_code (readonly)

Returns the value of attribute status_code



16
17
18
# File 'lib/fog/rackspace/core.rb', line 16

def status_code
  @status_code
end

- (Object) transaction_id (readonly)

Returns the value of attribute transaction_id



16
17
18
# File 'lib/fog/rackspace/core.rb', line 16

def transaction_id
  @transaction_id
end

Class Method Details

+ (Object) extract_message(data)



54
55
56
57
58
59
60
# File 'lib/fog/rackspace/core.rb', line 54

def self.extract_message(data)
  if data.is_a?(Hash)
    message = data.values.first['message'] if data.values.first.is_a?(Hash)
    message ||= data['message']
  end
  message || data.inspect
end

+ (Object) slurp(error, service = nil)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/rackspace/core.rb', line 23

def self.slurp(error, service=nil)
  data = nil
  message = nil
  status_code = nil

  if error.response
    status_code = error.response.status
    unless error.response.body.empty?
      begin
        data = Fog::JSON.decode(error.response.body)
        message = extract_message(data)
      rescue  => e
        Fog::Logger.warning("Received exception '#{e}' while decoding>> #{error.response.body}")
        message = error.response.body
        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.set_transaction_id(error, service)
  new_error
end

Instance Method Details

- (Object) set_transaction_id(error, service)



49
50
51
52
# File 'lib/fog/rackspace/core.rb', line 49

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

- (Object) to_s



18
19
20
21
# File 'lib/fog/rackspace/core.rb', line 18

def to_s
  status = status_code ? "HTTP #{status_code}" : "HTTP <Unknown>"
  "[#{status} | #{transaction_id}] #{super}"
end