Make sure RFE Message is only set to the response body payload. (#2539)

* Make sure RFE Message is only set to the response body payload.

* Add a note about the Message property.

* Jeff likes wordsmithing things for fun.
This commit is contained in:
Ahson Khan 2021-07-01 15:56:20 -07:00 committed by GitHub
parent d0ca42643f
commit 863e9871e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -55,6 +55,9 @@ namespace Azure { namespace Core {
/**
* @brief The error message from the service returned in the HTTP response.
*
* @note This string is purely for informational or diagnostic purposes, and should't be relied
* on at runtime.
*
*/
std::string Message;
@ -72,10 +75,7 @@ namespace Azure { namespace Core {
*
* @param message The error description.
*/
explicit RequestFailedException(std::string const& message)
: std::runtime_error(message), Message(message)
{
}
explicit RequestFailedException(std::string const& message) : std::runtime_error(message) {}
/**
* @brief Constructs a new `%RequestFailedException` object with an HTTP raw response.

View File

@ -32,17 +32,21 @@ namespace Azure { namespace Core {
RequestFailedException::RequestFailedException(
std::unique_ptr<Azure::Core::Http::RawResponse>& rawResponse)
: std::runtime_error(GetRawResponseField(rawResponse, "message"))
: std::runtime_error("Received an HTTP unsuccesful status code.")
{
auto& headers = rawResponse->GetHeaders();
// These are guaranteed to always be present in the rawResponse.
StatusCode = rawResponse->GetStatusCode();
ErrorCode = GetRawResponseField(rawResponse, "code");
ReasonPhrase = rawResponse->GetReasonPhrase();
RequestId = HttpShared::GetHeaderOrEmptyString(headers, HttpShared::MsRequestId);
ClientRequestId = HttpShared::GetHeaderOrEmptyString(headers, HttpShared::MsClientRequestId);
Message = this->what();
RawResponse = std::move(rawResponse);
// The response body may or may not have these fields
ErrorCode = GetRawResponseField(RawResponse, "code");
Message = GetRawResponseField(RawResponse, "message");
ClientRequestId = HttpShared::GetHeaderOrEmptyString(headers, HttpShared::MsClientRequestId);
RequestId = HttpShared::GetHeaderOrEmptyString(headers, HttpShared::MsRequestId);
}
std::string RequestFailedException::GetRawResponseField(