Class: RightScale::CloudApi::Parser::AWS::ResponseErrorV2

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud/aws/base/parsers/response_error.rb

Overview

AWS response error parser, case 2

Class Method Summary collapse

Class Method Details

.parse(response, options = {}) ⇒ Object

Parse HTTP error message from a response body

Examples:

# error is a response from ELB
parse(error) #=>
  400: ErrorName: SomethingIsWrong (RequestID: 32455505-2345-43245-f432-34543523451)

Parameters:

  • response (RightScale::CloudApi::HTTPResponse)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :xml_parser (Class)

Returns:

  • a String to be displayed/logged.

  • (String)


99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/cloud/aws/base/parsers/response_error.rb', line 99

def self.parse(response, options={})
  result = "#{response.code}: "
  body   = response.body.to_s
  if response['content-type'].to_s[/xml/] || body[/\A<\?xml /]
    hash = Utils::get_xml_parser_class(options[:xml_parser]).parse(body)
    error = hash["ErrorResponse"] && hash["ErrorResponse"]["Error"]
    if error
      request_id = hash["ErrorResponse"]["RequestID"] || hash["ErrorResponse"]["RequestId"] 
      result += "#{error['Type']}.#{error['Code']}: #{error['Message']} (RequestId: #{request_id})"
    end
  end
  result
end