XmlOutcome AWSXMLClient::MakeRequest(const Aws::String& uri, const Aws::AmazonWebServiceRequest& request, Http::HttpMethod method) const { HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, request, method)); if (!httpOutcome.IsSuccess()) { return XmlOutcome(httpOutcome.GetError()); } if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) { XmlDocument xmlDoc = XmlDocument::CreateFromXmlStream(httpOutcome.GetResult()->GetResponseBody()); if (!xmlDoc.WasParseSuccessful()) { AWS_LOG_ERROR(LOG_TAG, "Xml parsing for error failed with message %s", xmlDoc.GetErrorMessage().c_str()); return AWSError<CoreErrors>(CoreErrors::UNKNOWN, "Xml Parse Error", xmlDoc.GetErrorMessage(), false); } return XmlOutcome(AmazonWebServiceResult<XmlDocument>(std::move(xmlDoc), httpOutcome.GetResult()->GetHeaders(), httpOutcome.GetResult()->GetResponseCode())); } return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders())); }
AWSError<CoreErrors> AWSXMLClient::BuildAWSError(const std::shared_ptr<Http::HttpResponse>& httpResponse) const { if (!httpResponse) { return AWSError<CoreErrors>(CoreErrors::NETWORK_CONNECTION, "", "Unable to connect to endpoint", true); } if (httpResponse->GetResponseBody().tellp() < 1) { Aws::StringStream ss; ss << "No response body. Response code: " << httpResponse->GetResponseCode(); AWS_LOG_ERROR(LOG_TAG, ss.str().c_str()); return AWSError<CoreErrors>(CoreErrors::UNKNOWN, "", ss.str(), false); } assert(httpResponse->GetResponseCode() != HttpResponseCode::OK); // When trying to build an AWS Error from a response which is an FStream, we need to rewind the // file pointer back to the beginning in order to correctly read the input using the XML string iterator if ((httpResponse->GetResponseBody().tellp() > 0) && (httpResponse->GetResponseBody().tellg() > 0)) { httpResponse->GetResponseBody().seekg(0); } XmlDocument doc = XmlDocument::CreateFromXmlStream(httpResponse->GetResponseBody()); AWS_LOGSTREAM_TRACE(LOG_TAG, "Error response is " << doc.ConvertToString()); if (doc.WasParseSuccessful()) { XmlNode errorNode = doc.GetRootElement(); if (errorNode.GetName() != "Error") { errorNode = doc.GetRootElement().FirstChild("Error"); } if (!errorNode.IsNull()) { XmlNode codeNode = errorNode.FirstChild("Code"); XmlNode messageNode = errorNode.FirstChild("Message"); if (!(codeNode.IsNull() || messageNode.IsNull())) { return GetErrorMarshaller()->Marshall(StringUtils::Trim(codeNode.GetText().c_str()), StringUtils::Trim(messageNode.GetText().c_str())); } } } // An error occurred attempting to parse the httpResponse as an XML stream, so we're just // going to dump the XML parsing error and the http response code as a string Aws::StringStream ss; ss << "Unable to generate a proper httpResponse from the response stream. Response code: " << httpResponse->GetResponseCode(); return GetErrorMarshaller()->Marshall(StringUtils::Trim(doc.GetErrorMessage().c_str()), ss.str().c_str()); }