Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WindowsAzure.Storage v2 StorageException

I'm migrating from WindowsAzure.StorageClient 1.7 to WindowsAzure.Storage 2.0, and I'm working right now on the management of the exceptions. Following this guide and other sources, I found out I had to migrate from

try
{
    // Something
}
catch (StorageClientException e)
{
    switch (e.ErrorCode)
    {
        case StorageErrorCode.ContainerNotFound:
        case StorageErrorCode.ResourceNotFound:
        case StorageErrorCode.BlobNotFound:
        case StorageErrorCode.ConditionFailed:
            // Do something
    }
}

to

try
{
    // Something
}
catch (StorageException e)
{
    switch (e.RequestInformation.ExtendedErrorInformation.ErrorCode)
    {
        case StorageErrorCodeStrings.ContainerNotFound:
        case StorageErrorCodeStrings.ResourceNotFound:
        case BlobErrorCodeStrings.BlobNotFound:
        case StorageErrorCodeStrings.ConditionNotMet:
            // Do something
    }
}

Looks simple. The problem is ExtendedErrorInformation is always equal to null. The HttpStatusMessage instead says 'The specified blob does not exist.', as it should.

I thought it was caused by the simulator of the test environment, but trying it in a real Azure environment drived me to the same situation.

Any idea?

like image 747
Mattia Vitturi Avatar asked Jan 16 '13 16:01

Mattia Vitturi


1 Answers

Another option is to look at the RequestInformation.HttpStatusCode instead. This seems to be more reliable anyway. Your code translates rather easily to:

try
{
    // Something
}
catch (StorageException e)
{
    switch (e.RequestInformation.HttpStatusCode)
    {
        case (int)HttpStatusCode.NotFound:
        case (int)HttpStatusCode.PreconditionFailed:
        // Do something
    }
}
like image 148
Brian Reischl Avatar answered Sep 28 '22 11:09

Brian Reischl