我下面的代码更改:错误处理为Windows Azure存储迁移从1.7到2.0
try
{
blob.FetchAttributes();
}
catch (StorageClientException e)
{
if (e.ErrorCode == StorageErrorCode.ResourceNotFound)
....
}
到:
try
{
blob.FetchAttributes();
}
catch (StorageException e)
{
if (e.RequestInformation.ExtendedErrorInformation.ErrorCode == StorageErrorCodeStrings.ResourceNotFound)
....
}
后我运行它,它给了我一个NullException因为:
e.RequestInformation.ExtendedErrorInformation = NULL,
但是
e.RequestInformation.HTTPStatusMessage =“指定的blob不存在。”
和
e.RequestInformation.HTTPStatusCode = 404
我想,以测试HttpStatusMessage,但我觉得它是不是安全的做到这一点,因为消息可能会随时间而改变,任何人都可以帮助我在这种情况下我应该怎么做,如果我想保持我原来的逻辑行为?
非常感谢您的帮助,因此为了检查服务器是否返回响应主体,我该怎么做?如果(e.RequestInformation.HTTPStatusCode!= 404) 这个工作吗? – Talen 2013-03-28 19:13:49
你实际上可以检查ExtendedErrorInformation属性本身。如果它不为空,则意味着服务器返回了一个包含更多错误信息的响应主体。然后你可以进一步调查发生了什么。 – 2013-03-29 05:34:09