Skip to content

Commit 0203323

Browse files
authored
Storage/STG99 Made error message for invalid x-ms-version more user-friendly (#6613)
* add invalid version erorr message support * Update find logic
1 parent 5464be2 commit 0203323

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,4 +2264,20 @@ namespace Azure { namespace Storage { namespace Test {
22642264
blobProperties = versionClient.GetProperties().Value;
22652265
EXPECT_TRUE(blobProperties.HasLegalHold);
22662266
}
2267+
2268+
TEST_F(BlockBlobClientTest, InvalidVersionMessage_LIVEONLY_)
2269+
{
2270+
Blobs::BlobClientOptions options;
2271+
options.ApiVersion = "3015-11-11";
2272+
auto blobClient = GetBlockBlobClientForTest(LowercaseRandomString(), options);
2273+
try
2274+
{
2275+
blobClient.Download();
2276+
}
2277+
catch (const StorageException& e)
2278+
{
2279+
EXPECT_EQ(e.ErrorCode, _internal::InvalidHeaderValueErrorCode);
2280+
EXPECT_EQ(e.Message, _internal::InvalidVersionHeaderMessage);
2281+
}
2282+
}
22672283
}}} // namespace Azure::Storage::Test

sdk/storage/azure-storage-common/inc/azure/storage/common/internal/constants.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ namespace Azure { namespace Storage { namespace _internal {
2121
constexpr static const char* HttpHeaderContentType = "content-type";
2222
constexpr static const char* HttpHeaderContentLength = "content-length";
2323
constexpr static const char* HttpHeaderContentRange = "content-range";
24+
constexpr static const char* InvalidHeaderValueErrorCode = "InvalidHeaderValue";
25+
constexpr static const char* InvalidVersionHeaderMessage
26+
= "The provided service version is not enabled on this storage account. Please see "
27+
"https://learn.microsoft.com/rest/api/storageservices/"
28+
"versioning-for-the-azure-storage-services for additional information.";
2429

2530
constexpr int ReliableStreamRetryCount = 3;
2631
}}} // namespace Azure::Storage::_internal

sdk/storage/azure-storage-common/src/storage_exception.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ namespace Azure { namespace Storage {
147147
errorCode = response->GetHeaders().at("x-ms-error-code");
148148
}
149149

150+
// Optimize error messages
151+
const auto headerName = additionalInformation.find("HeaderName");
152+
if (errorCode == _internal::InvalidHeaderValueErrorCode
153+
&& headerName != additionalInformation.end() && headerName->second == "x-ms-version")
154+
{
155+
message = _internal::InvalidVersionHeaderMessage;
156+
}
157+
150158
StorageException result = StorageException(
151159
std::to_string(static_cast<std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
152160
httpStatusCode))

0 commit comments

Comments
 (0)