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?
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With