class Fog::Ecloud::Errors::ServiceError

The parent class for all errors in the Fog::Compute::Ecloud module.

Attributes

minor_error_code[R]

@!attribute [r] #status_code

@return [Integer] the HTTP status code returned
response_data[R]

@!attribute [r] #status_code

@return [Integer] the HTTP status code returned
status_code[R]

@!attribute [r] #status_code

@return [Integer] the HTTP status code returned

Public Class Methods

extract_message(data) click to toggle source

Parse the response body for an error message

@param [Hash] data the decoded XML response

@return [String] the error message, if found, otherwise the raw data

# File lib/fog/compute/ecloud/errors.rb, line 69
def self.extract_message(data)
  if data.is_a?(Hash)
    message = data[:message]
  end
  message || data.inspect
end
extract_minor_code(data) click to toggle source

Parse the response body for the minor error code

@param [Hash] data the decoded XML response

@return [String] the error minor error code, if found, otherwise nil

# File lib/fog/compute/ecloud/errors.rb, line 81
def self.extract_minor_code(data)
  minor_code = nil
  if data.is_a?(Hash)
    minor_code = data[:minorErrorCode]
  end
  minor_code
end
slurp(error) click to toggle source

Parse the response from the HTTP request to create a user friendly

message, including HTTP response code and error message (if any)

@param [Object] error the error object from the rescue block

@return [Object] the new error object

Calls superclass method
# File lib/fog/compute/ecloud/errors.rb, line 29
def self.slurp(error)
  data = nil
  message = nil
  status_code = nil
  minor_code = nil

  if error.response
    status_code = error.response.status
    unless error.response.body.empty?
      begin
        document = Fog::ToHashDocument.new
        parser = Nokogiri::XML::SAX::PushParser.new(document)
        parser << error.response.body
        parser.finish

        data = document.body

        message = extract_message(data)
        minor_code = extract_minor_code(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.instance_variable_set(:@minor_error_code, minor_code)
  new_error
end

Public Instance Methods

to_s() click to toggle source

Make the HTTP status code pretty

@return [String] the cleaned up status code

# File lib/fog/compute/ecloud/errors.rb, line 17
def to_s
  status = status_code ? "HTTP #{status_code}" : "HTTP <Unknown>"
  minor_code = minor_error_code ? minor_error_code : "Unknown"
  "[#{status} - #{minor_code}] #{super}"
end