# File lib/AWS/Autoscaling.rb, line 31
31:       def aws_error?(response)
32: 
33:         # return false if we got a HTTP 200 code,
34:         # otherwise there is some type of error (40x,50x) and
35:         # we should try to raise an appropriate exception
36:         # from one of our exception classes defined in
37:         # exceptions.rb
38:         return false if response.is_a?(Net::HTTPSuccess)
39: 
40:         # parse the XML document so we can walk through it
41:         doc = REXML::Document.new(response.body)
42: 
43:         # Check that the Error element is in the place we would expect.
44:         # and if not raise a generic error exception
45:         unless doc.root.elements[1].name == "Error"
46:           raise Error, "Unexpected error format. response.body is: #{response.body}"
47:         end
48: 
49:         # An valid error response looks like this:
50:         # <?xml version="1.0"?><Response><Errors><Error><Code>InvalidParameterCombination</Code><Message>Unknown parameter: foo</Message></Error></Errors><RequestID>291cef62-3e86-414b-900e-17246eccfae8</RequestID></Response>
51:         # AWS EC2 throws some exception codes that look like Error.SubError.  Since we can't name classes this way
52:         # we need to strip out the '.' in the error 'Code' and we name the error exceptions with this
53:         # non '.' name as well.
54:         error_code    = doc.root.elements['//ErrorResponse/Error/Code'].text.gsub('.', '')
55:         error_message = doc.root.elements['//ErrorResponse/Error/Message'].text
56: 
57:         # Raise one of our specific error classes if it exists.
58:         # otherwise, throw a generic EC2 Error with a few details.
59:         if AWS.const_defined?(error_code)
60:           raise AWS.const_get(error_code), error_message
61:         else
62:           raise AWS::Error, error_message
63:         end
64: 
65:       end