0

I change the following code from:

try
{
    blob.FetchAttributes();
}
catch (StorageClientException e)
{
    if (e.ErrorCode == StorageErrorCode.ResourceNotFound)
        ....
}

to:

try
{
    blob.FetchAttributes();
}
catch (StorageException e)
{
    if (e.RequestInformation.ExtendedErrorInformation.ErrorCode == StorageErrorCodeStrings.ResourceNotFound)
        ....
}

After i run it, it gives me a NullException because:

e.RequestInformation.ExtendedErrorInformation = NULL,

but

e.RequestInformation.HTTPStatusMessage = "The specified blob does not exist."

and

e.RequestInformation.HTTPStatusCode = 404

I was thinking to test for the HttpStatusMessage, but i feel it is not that safe to do it since the Message could change over time, Can anyone help me what should I do in this case if i want to keep my original logic behavior?

1 Answer 1

1

ErrorCode in the old library is actually different than the ErrorCode in the new library. The old library tried to classify errors based on exception type, HTTP status code, and the error code returned by the server if any. In some cases, this was causing more confusion because different errors were mapped to a single value of StorageErrorCode.

Hence, in Azure Storage Client Library 2.0, the legacy StorageErrorCode enum no longer exists. Instead, we ask our users to check the HTTP status code directly. If the server returns a response body, that can contain further information as also described at the Status and Error Codes article. When this data exists, ErrorCode will be populated accordingly.

In your example, FetchAttributes issues a Get Blob Properties request, which does not return a response body. That is why ExtendedErrorInformation was null.

2
  • Thank you so much for your help, so in order to check if the server returns a response body, what should i do? if(e.RequestInformation.HTTPStatusCode != 404) will this work?
    – Talen
    Mar 28, 2013 at 19:13
  • You can actually check the ExtendedErrorInformation property itself. If it is not null, it means the server returned a response body with more error information. Then you can investigate further what happened. Mar 29, 2013 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.