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