Azure / azure-sdk-for-cpp

This repository is for active development of the Azure SDK for C++. For consumers of the SDK we recommend visiting our versioned developer docs at https://azure.github.io/azure-sdk-for-cpp.
MIT License
181 stars 126 forks source link

How to get AuthenticationErrorDetail for 403 responses? #4943

Open mattdurak opened 1 year ago

mattdurak commented 1 year ago

Query/Question

According to these docs, https://techcommunity.microsoft.com/t5/azure-paas-blog/troubleshooting-the-403-error-for-user-delegation-sas-in-azure/ba-p/3294999 I should be able to troubleshoot 403 authentication errors by looking at the AuthenticationErrorDetail.

However, the exception in this SDK (StorageException) does not seem to have such a field.

When I get exceptions like this: "403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature." I don't also get the message like in the link above that tells me what was wrong with the authorization header.

Why is this not a Bug or a feature Request?

I'm not sure if this is a bug or just missing documentation on how to get the AuthenticationErrorDetail from StorageException.

Setup (please complete the following information if applicable):

Jinming-Hu commented 1 year ago

Hi @mattdurak there are a few things you can check in the exception, and depending on which API you're calling, some of the fields may be empty.

  try
  {
    auto properties = blobClient.Download().Value;
  }
  catch (Azure::Storage::StorageException& e) {
    std::cout << e.ReasonPhrase << std::endl;
    std::cout << e.RequestId << std::endl;
    std::cout << e.ErrorCode << std::endl;
    std::cout << e.Message << std::endl;
    for (const auto& i : e.AdditionalInformation)
    {
      std::cout << i.first << ": " << i.second << std::endl;
    }
  }

If you cannot figure out the problem with the output from above code, you can contact us with the RequestId field, we can help you check from server-side.