public static bool IsProblemDoesNotExist(this StorageException exception) { return(exception.ParseExtendedErrorInformation( (errorCode, message) => { if (errorCode == ExtendedErrorInformationCodes.TableNotFound) { return true; } if (errorCode == ExtendedErrorInformationCodes.BlobNotFound) { return true; } return false; }, () => { if (exception.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound) { return true; } if (exception.InnerException is System.Net.WebException) { var webEx = (System.Net.WebException)exception.InnerException; if (webEx.Response is System.Net.HttpWebResponse) { var httpResponse = (System.Net.HttpWebResponse)webEx.Response; return (httpResponse.StatusCode == System.Net.HttpStatusCode.NotFound); } } return false; })); }
public static TResult ParseStorageException <TResult>(this StorageException storageException, Func <ExtendedErrorInformationCodes, string, TResult> onParsed, Func <TResult> onUnableToParse) { return(storageException.ParseExtendedErrorInformation( onParsed, () => { if (storageException.IsProblemTimeout()) { return onParsed(ExtendedErrorInformationCodes.Timeout, "The request to AST timed out."); } if (storageException.InnerException is System.Net.WebException) { var webEx = storageException.InnerException as System.Net.WebException; if (webEx.Response is System.Net.HttpWebResponse) { var httpWebResponse = webEx.Response as System.Net.HttpWebResponse; try { var responseContent = webEx.Message; // await httpWebResponse.GetResponseStream().ReadAsStringAsync(); System.Diagnostics.Debug.WriteLine($"AST replied:{responseContent}"); return onParsed(ExtendedErrorInformationCodes.General, responseContent); } catch (Exception exFromStream) { exFromStream.GetType(); // Suppress warning return onUnableToParse(); } } } return onUnableToParse(); })); }
public static bool IsProblemResourceAlreadyExists(this StorageException exception) { return(exception.ParseExtendedErrorInformation( (errorCode, errorMessage) => errorCode == ExtendedErrorInformationCodes.EntityAlreadyExists, () => false)); }
public static bool IsProblemPropertyValueTooLarge(this StorageException exception) { return(exception.ParseExtendedErrorInformation( (errorCode, errorMessage) => errorCode == ExtendedErrorInformationCodes.PropertyValueTooLarge, () => false)); }