in Gems/AWSCore/Code/Include/Framework/ServiceRequestJob.h [289:418]
void ProcessResponse(const std::shared_ptr<Aws::Http::HttpResponse>& response) override
{
if (ServiceClientJobType::IsCancelled())
{
RequestType::error.type = Error::TYPE_NETWORK_ERROR;
RequestType::error.message = "Job canceled while waiting for a response.";
}
else if (!response)
{
RequestType::error.type = Error::TYPE_NETWORK_ERROR;
RequestType::error.message = "An unknown error occurred while making the request.";
}
else
{
#ifdef _DEBUG
// Code assumes application/json; charset=utf-8
const Aws::String& contentType = response->GetContentType();
AZ_Error(
ServiceClientJobType::COMPONENT_DISPLAY_NAME,
contentType.find("application/json") != AZStd::string::npos &&
(contentType.find("charset") == AZStd::string::npos ||
contentType.find("utf-8") != AZStd::string::npos),
"Service response content type is not application/json; charset=utf-8: %s", contentType.c_str()
);
#endif
int responseCode = static_cast<int>(response->GetResponseCode());
Aws::IOStream& responseBody = response->GetResponseBody();
#ifdef _DEBUG
std::istreambuf_iterator<AZStd::string::value_type> eos;
AZStd::string responseContent = AZStd::string{ std::istreambuf_iterator<AZStd::string::value_type>(responseBody),eos };
AZ_Printf(ServiceClientJobType::COMPONENT_DISPLAY_NAME, "Processing %d response: %s.", responseCode, responseContent.c_str());
responseBody.clear();
responseBody.seekg(0);
#endif
static AZ::EnvironmentVariable<bool> envVar = AZ::Environment::FindVariable<bool>("AWSLogVerbosity");
if (envVar && envVar.Get())
{
ShowRequestLog(response);
}
JsonInputStream stream{ responseBody };
if (responseCode >= 200 && responseCode <= 299)
{
ReadResponseObject(stream);
}
else
{
ReadErrorObject(responseCode, stream);
}
}
if (WasSuccess())
{
OnSuccess();
}
else
{
AZStd::string requestContent;
AZStd::string responseContent;
if (response)
{
// Get request and response content. Not attempting to do any charset
// encoding/decoding, so the display may not be correct but it should
// work fine for the usual ascii and utf8 content.
std::istreambuf_iterator<AZStd::string::value_type> eos;
std::shared_ptr<Aws::IOStream> requestStream = response->GetOriginatingRequest().GetContentBody();
if (requestStream)
{
requestStream->clear();
requestStream->seekg(0);
requestContent = AZStd::string{ std::istreambuf_iterator<AZStd::string::value_type>(*requestStream.get()),eos };
// Replace the character "%" with "%%" to prevent the error when printing the string that contains the percentage sign
requestContent = EscapePercentCharsInString(requestContent);
}
Aws::IOStream& responseStream = response->GetResponseBody();
responseStream.clear();
responseStream.seekg(0);
responseContent = AZStd::string{ std::istreambuf_iterator<AZStd::string::value_type>(responseStream),eos };
}
#if defined(AZ_ENABLE_TRACING)
AZStd::string message = AZStd::string::format("An %s error occurred when performing %s %s on service %s using %s: %s\n\nRequest Content:\n%s\n\nResponse Content:\n%s\n\n",
RequestType::error.type.c_str(),
ServiceRequestJobType::HttpMethodToString(RequestType::Method()),
RequestType::Path(),
RequestType::ServiceTraits::ServiceName,
response ? response->GetOriginatingRequest().GetURIString().c_str() : "NULL",
RequestType::error.message.c_str(),
requestContent.c_str(),
responseContent.c_str()
);
// This is determined by AZ::g_maxMessageLength defined in in dev\Code\Framework\AzCore\AzCore\Debug\Trace.cpp.
// It has the value 4096, but there is the timestamp, etc., to account for so we reduce it by a few characters.
const int MAX_MESSAGE_LENGTH = 4096 - 128;
// Replace the character "%" with "%%" to prevent the error when printing the string that contains the percentage sign
message = EscapePercentCharsInString(message);
if (message.size() > MAX_MESSAGE_LENGTH)
{
int offset = 0;
while (offset < message.size())
{
int count = static_cast<int>((offset + MAX_MESSAGE_LENGTH < message.size()) ? MAX_MESSAGE_LENGTH : message.size() - offset);
AZ_Warning(ServiceClientJobType::COMPONENT_DISPLAY_NAME, false, message.substr(offset, count).c_str());
offset += MAX_MESSAGE_LENGTH;
}
}
else
{
AZ_Warning(ServiceClientJobType::COMPONENT_DISPLAY_NAME, false, message.c_str());
}
#endif
OnFailure();
}
}