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