diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index da0c38ff8..409f70cf2 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -39,6 +39,7 @@ - Removed `Azure::Core::DateTime::GetRfc3339String()`: `Azure::Core::DateTime::ToString()` was extended to provide the same functionality. - Changed the constructor of `Azure::IO::FileBodyStream` to accept a file name directly and take ownership of opening/closing the file, instead of accepting a file descriptor, offset, and length. - Renamed the `Range` type to `HttpRange` within the `Azure::Core::Http` namespace. +- Removed `Azure::Core::Http::InvalidHeaderException` and throw `std::invalid_argument` if the user provides invalid header arguments. - Moved the `Base64Encode()` and `Base64Decode()` functions to be static members of a `Convert` class within the `Azure::Core` namespace. - Moved `Azure::Core::Response` to `Azure::Response`. - Moved `Azure::Core::ETag` to `Azure::ETag`. 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 e6655c40d..98653f8ae 100644 --- a/sdk/core/azure-core/inc/azure/core/http/http.hpp +++ b/sdk/core/azure-core/inc/azure/core/http/http.hpp @@ -58,24 +58,6 @@ namespace Azure { namespace Core { namespace Http { } }; - /** - * @brief An invalid header key name in #Azure::Core::Http::Request or - * #Azure::Core::Http::RawResponse. - * - */ - class InvalidHeaderException : public Azure::Core::RequestFailedException { - public: - /** - * @brief An invalid header key name detected in the HTTP request or response. - * - * @param message The error description. - */ - explicit InvalidHeaderException(std::string const& message) - : Azure::Core::RequestFailedException(message) - { - } - }; - /** * @brief Defines the possible HTTP status codes. */ diff --git a/sdk/core/azure-core/src/http/http.cpp b/sdk/core/azure-core/src/http/http.cpp index 93f6d2651..aaa83ab0a 100644 --- a/sdk/core/azure-core/src/http/http.cpp +++ b/sdk/core/azure-core/src/http/http.cpp @@ -156,7 +156,7 @@ void Azure::Core::_detail::InsertHeaderWithValidation( { if (validChars[static_cast(headerName[index])] == 0) { - throw InvalidHeaderException("Invalid header: " + headerName); + throw std::invalid_argument("Invalid header: " + headerName); } } // insert (override if duplicated) diff --git a/sdk/core/azure-core/src/http/raw_response.cpp b/sdk/core/azure-core/src/http/raw_response.cpp index e4f1043b0..e10137094 100644 --- a/sdk/core/azure-core/src/http/raw_response.cpp +++ b/sdk/core/azure-core/src/http/raw_response.cpp @@ -26,7 +26,7 @@ void RawResponse::SetHeader(uint8_t const* const first, uint8_t const* const las if (end == last) { - throw InvalidHeaderException("Invalid header. No delimiter ':' found."); + throw std::invalid_argument("Invalid header. No delimiter ':' found."); } // Always toLower() headers diff --git a/sdk/core/azure-core/test/ut/http.cpp b/sdk/core/azure-core/test/ut/http.cpp index a2fcb0876..1730e5837 100644 --- a/sdk/core/azure-core/test/ut/http.cpp +++ b/sdk/core/azure-core/test/ut/http.cpp @@ -33,7 +33,7 @@ namespace Azure { namespace Core { namespace Test { req.GetHeaders(), expected); - EXPECT_THROW(req.SetHeader("invalid()", "header"), std::runtime_error); + EXPECT_THROW(req.SetHeader("invalid()", "header"), std::invalid_argument); // same header will just override std::pair expectedOverride("valid", "override"); @@ -78,8 +78,7 @@ namespace Azure { namespace Core { namespace Test { response.GetHeaders(), expected); - EXPECT_THROW( - response.SetHeader("invalid()", "header"), Azure::Core::Http::InvalidHeaderException); + EXPECT_THROW(response.SetHeader("invalid()", "header"), std::invalid_argument); // same header will just override std::pair expectedOverride("valid", "override"); @@ -107,9 +106,8 @@ namespace Azure { namespace Core { namespace Test { expected2); // Response SetHeader overload method to add from string - EXPECT_THROW(response.SetHeader("inv(): header"), Azure::Core::Http::InvalidHeaderException); - EXPECT_THROW( - response.SetHeader("no delimiter header"), Azure::Core::Http::InvalidHeaderException); + EXPECT_THROW(response.SetHeader("inv(): header"), std::invalid_argument); + EXPECT_THROW(response.SetHeader("no delimiter header"), std::invalid_argument); // adding header after previous error just happened on add from string EXPECT_NO_THROW(response.SetHeader("valid3: header3"));