Azure / azure-storage-cpp

Microsoft Azure Storage Client Library for C++
http://azure.github.io/azure-storage-cpp
Apache License 2.0
132 stars 147 forks source link

storage_exception m_http_status_code = 0 with invalid username #319

Closed arginite closed 4 years ago

arginite commented 4 years ago

What is the expected contents of the storage_exception exception (in picticular what should http_status_code contain) caught by this code when invalid storage credentials (incorrect account_name or account_key) are used?

Also what would be the content of the same exception with a network issue that prevents connection to an end point but valid credentials?

try {
        azure::storage::storage_credentials storageCredentials
            = azure::storage::storage_credentials(azureAccountName, azureAccountKey);

        azure::storage::cloud_storage_account storageAccount
            = azure::storage::cloud_storage_account(storageCredentials, useHTTPS);

        if (true == storageAccount.is_initialized()) {
            blobClient = storageAccount.create_cloud_blob_client();

            azure::storage::cloud_blob_container blobContainer = blobClient.get_container_reference(L"ContainerName");

            blobContainer.exists();
        }
    }
    catch (azure::storage::storage_exception & storageException) {
        web::http::status_code statusCode = storageException.result().http_status_code();
    }
Jinming-Hu commented 4 years ago

Hi @arginite It depends on the situation.

The endpoint contains storage account name, like 'my_account.blob.core.windows.net`.

  1. If a nonexistent storage account is provided, then the endpoint is invalid and DNS record cannot be found. What will happen is up to the underlying HTTP client, usually timeout. The HTTP status code in exception would be undefined, since the HTTP connection isn't established at all.

  2. If the shared key is not a valid base64-encoded string, std::runtime_error will be thrown.

  3. If the shared key is a valid base64-encoded string but the key is incorrect (e.g. revoked), HTTP status code 403 will be returned.

  4. Network issue, this is pretty much the same as case 1.

arginite commented 4 years ago

@JinmingHu-MSFT

Thanks for the response that makes sense. Is this documented anywhere?

Jinming-Hu commented 4 years ago

Is this documented anywhere?

I don't think so.