我下面的代碼更改:錯誤處理爲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