diff --git a/sdk/core/azure-core/inc/azure/core/context.hpp b/sdk/core/azure-core/inc/azure/core/context.hpp index a8da7f6f8..33cb2ea2f 100644 --- a/sdk/core/azure-core/inc/azure/core/context.hpp +++ b/sdk/core/azure-core/inc/azure/core/context.hpp @@ -30,11 +30,9 @@ namespace Azure { namespace Core { /** * @brief Constructs an `OperationCancelledException` with message string as the description. * - * @param whatArg The explanatory string. + * @param what The explanatory string. */ - explicit OperationCancelledException(std::string const& whatArg) : std::runtime_error(whatArg) - { - } + explicit OperationCancelledException(std::string const& what) : std::runtime_error(what) {} }; /** diff --git a/sdk/core/azure-core/inc/azure/core/credentials/credentials.hpp b/sdk/core/azure-core/inc/azure/core/credentials/credentials.hpp index 71ae40d2b..94a033eeb 100644 --- a/sdk/core/azure-core/inc/azure/core/credentials/credentials.hpp +++ b/sdk/core/azure-core/inc/azure/core/credentials/credentials.hpp @@ -98,15 +98,15 @@ namespace Azure { namespace Core { namespace Credentials { * @brief An exception that gets thrown when an authentication error occurs. */ class AuthenticationException final : public std::exception { - std::string m_whatArg; + std::string m_what; public: /** * @brief Constructs `%AuthenticationException` with a message string. * - * @param whatArg The explanatory string. + * @param what The explanatory string. */ - explicit AuthenticationException(std::string whatArg) : m_whatArg(std::move(whatArg)) {} + explicit AuthenticationException(std::string what) : m_what(std::move(what)) {} /** * Gets the explanatory string. @@ -115,6 +115,6 @@ namespace Azure { namespace Core { namespace Credentials { * * @return C string with explanatory information. */ - char const* what() const noexcept override { return m_whatArg.c_str(); } + char const* what() const noexcept override { return m_what.c_str(); } }; }}} // namespace Azure::Core::Credentials diff --git a/sdk/core/azure-core/inc/azure/core/exception.hpp b/sdk/core/azure-core/inc/azure/core/exception.hpp index 2d910587c..939382939 100644 --- a/sdk/core/azure-core/inc/azure/core/exception.hpp +++ b/sdk/core/azure-core/inc/azure/core/exception.hpp @@ -73,9 +73,9 @@ namespace Azure { namespace Core { * @note An Exception without an HTTP raw response represents an exception that happened * before sending the request to the server. * - * @param whatArg The explanatory string. + * @param what The explanatory string. */ - explicit RequestFailedException(std::string const& whatArg) : std::runtime_error(whatArg) {} + explicit RequestFailedException(std::string const& what) : std::runtime_error(what) {} /** * @brief Constructs a new `%RequestFailedException` object with an HTTP raw response. @@ -85,12 +85,12 @@ namespace Azure { namespace Core { * Service exception which derives from this exception uses its constructor to parse the HTTP * raw response adding the service specific values to the exception. * - * @param message The error description. + * @param what The explanatory string. * @param rawResponse The HTTP raw response from the service. */ explicit RequestFailedException( - const std::string& message, - std::unique_ptr rawResponse); + const std::string& what, + std::unique_ptr& rawResponse); /** * @brief Constructs a new `%RequestFailedException` object with an HTTP raw response. diff --git a/sdk/core/azure-core/inc/azure/core/http/http.hpp b/sdk/core/azure-core/inc/azure/core/http/http.hpp index 478f2a251..d9cc9bab9 100644 --- a/sdk/core/azure-core/inc/azure/core/http/http.hpp +++ b/sdk/core/azure-core/inc/azure/core/http/http.hpp @@ -61,10 +61,9 @@ namespace Azure { namespace Core { namespace Http { * @remark The transport policy will throw this error whenever the transport adapter fail to * perform a request. * - * @param whatArg The explanatory string. + * @param what The explanatory string. */ - explicit TransportException(std::string const& whatArg) - : Azure::Core::RequestFailedException(whatArg) + explicit TransportException(std::string const& what) : Azure::Core::RequestFailedException(what) { } }; diff --git a/sdk/core/azure-core/src/exception.cpp b/sdk/core/azure-core/src/exception.cpp index e302704d1..fe6710848 100644 --- a/sdk/core/azure-core/src/exception.cpp +++ b/sdk/core/azure-core/src/exception.cpp @@ -16,25 +16,11 @@ using namespace Azure::Core::Http::_internal; namespace Azure { namespace Core { RequestFailedException::RequestFailedException( - const std::string& message, - std::unique_ptr rawResponse) - : std::runtime_error(message), Message(message) - { - auto const& headers = rawResponse->GetHeaders(); - - StatusCode = rawResponse->GetStatusCode(); - ReasonPhrase = rawResponse->GetReasonPhrase(); - RequestId = HttpShared::GetHeaderOrEmptyString(headers, HttpShared::MsRequestId); - ClientRequestId = HttpShared::GetHeaderOrEmptyString(headers, HttpShared::MsClientRequestId); - Message = message; - RawResponse = std::move(rawResponse); - } - - RequestFailedException::RequestFailedException( + const std::string& what, std::unique_ptr& rawResponse) - : std::runtime_error("Received an HTTP unsuccessful status code.") + : std::runtime_error(what) { - auto& headers = rawResponse->GetHeaders(); + const auto& headers = rawResponse->GetHeaders(); // These are guaranteed to always be present in the rawResponse. StatusCode = rawResponse->GetStatusCode(); @@ -49,6 +35,12 @@ namespace Azure { namespace Core { RequestId = HttpShared::GetHeaderOrEmptyString(headers, HttpShared::MsRequestId); } + RequestFailedException::RequestFailedException( + std::unique_ptr& rawResponse) + : RequestFailedException("Received an HTTP unsuccessful status code.", rawResponse) + { + } + std::string RequestFailedException::GetRawResponseField( std::unique_ptr& rawResponse, std::string fieldName) diff --git a/sdk/core/azure-core/test/ut/exception_test.cpp b/sdk/core/azure-core/test/ut/exception_test.cpp index d520baf22..b74cb60ba 100644 --- a/sdk/core/azure-core/test/ut/exception_test.cpp +++ b/sdk/core/azure-core/test/ut/exception_test.cpp @@ -93,13 +93,13 @@ TEST(RequestFailedException, Message) response->SetBodyStream(std::make_unique( responseBodyStream, sizeof(responseBodyStream) - 1)); - auto exception = Azure::Core::RequestFailedException("Msg", std::move(response)); + auto exception = Azure::Core::RequestFailedException("what", response); EXPECT_EQ(exception.StatusCode, Azure::Core::Http::HttpStatusCode::ServiceUnavailable); - EXPECT_EQ(exception.Message, "Msg"); - EXPECT_EQ(exception.ErrorCode, ""); + EXPECT_EQ(exception.Message, "JT"); + EXPECT_EQ(exception.ErrorCode, "503"); EXPECT_EQ(exception.RequestId, "1"); EXPECT_EQ(exception.ClientRequestId, "2"); EXPECT_EQ(exception.ReasonPhrase, "retry please :"); - EXPECT_EQ(exception.what(), std::string("Msg")); + EXPECT_EQ(exception.what(), std::string("what")); } diff --git a/sdk/storage/azure-storage-common/inc/azure/storage/common/storage_exception.hpp b/sdk/storage/azure-storage-common/inc/azure/storage/common/storage_exception.hpp index 166aeba9d..f8a026480 100644 --- a/sdk/storage/azure-storage-common/inc/azure/storage/common/storage_exception.hpp +++ b/sdk/storage/azure-storage-common/inc/azure/storage/common/storage_exception.hpp @@ -21,9 +21,9 @@ namespace Azure { namespace Storage { /** * @brief Constructs a #StorageException with a message. * - * @param whatArg The explanatory string. + * @param what The explanatory string. */ - explicit StorageException(const std::string& whatArg) : RequestFailedException(whatArg) {} + explicit StorageException(const std::string& what) : RequestFailedException(what) {} /** * Some storage-specific information in response body.