# File lib/AWS.rb, line 290
290:       def aws_error?(response)
291: 
292:         # return false if we got a HTTP 200 code,
293:         # otherwise there is some type of error (40x,50x) and
294:         # we should try to raise an appropriate exception
295:         # from one of our exception classes defined in
296:         # exceptions.rb
297:         return false if response.is_a?(Net::HTTPSuccess)
298: 
299:         # parse the XML document so we can walk through it
300:         doc = REXML::Document.new(response.body)
301: 
302:         # Check that the Error element is in the place we would expect.
303:         # and if not raise a generic error exception
304:         unless doc.root.elements['Errors'].elements['Error'].name == 'Error'
305:           raise Error, "Unexpected error format. response.body is: #{response.body}"
306:         end
307: 
308:         # An valid error response looks like this:
309:         # <?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>
310:         # AWS throws some exception codes that look like Error.SubError.  Since we can't name classes this way
311:         # we need to strip out the '.' in the error 'Code' and we name the error exceptions with this
312:         # non '.' name as well.
313:         error_code    = doc.root.elements['Errors'].elements['Error'].elements['Code'].text.gsub('.', '')
314:         error_message = doc.root.elements['Errors'].elements['Error'].elements['Message'].text
315: 
316:         # Raise one of our specific error classes if it exists.
317:         # otherwise, throw a generic EC2 Error with a few details.
318:         if AWS.const_defined?(error_code)
319:           raise AWS.const_get(error_code), error_message
320:         else
321:           raise AWS::Error, error_message
322:         end
323: 
324:       end