本文介绍了WindowsAzure.Storage V2 StorageException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从WindowsAzure.StorageClient 1.7迁移到WindowsAzure.Storage 2.0,和我的工作,现在在例外的管理。在此之后的guide和其他来源,我发现我不得不从

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
    }
}

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

看起来很简单。现在的问题是ExtendedErrorInformation总是等于空。该HttpStatusMessage,而不是说'指定的一滴不存在。,因为它应该。

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

我以为是在测试环境模拟器造成的,而是试图在一个真正的Azure环境掘进我同样的情况。

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.

你知道吗?

推荐答案

另一种方法是看 RequestInformation.HttpStatus code 代替。这似乎是更可靠反正。您的code转换而容易:

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
    }
}

这篇关于WindowsAzure.Storage V2 StorageException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 19:56