Exemplo n.º 1
0
        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;
            }));
        }
Exemplo n.º 2
0
        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();
            }));
        }
Exemplo n.º 3
0
 public static bool IsProblemResourceAlreadyExists(this StorageException exception)
 {
     return(exception.ParseExtendedErrorInformation(
                (errorCode, errorMessage) => errorCode == ExtendedErrorInformationCodes.EntityAlreadyExists,
                () => false));
 }
Exemplo n.º 4
0
 public static bool IsProblemPropertyValueTooLarge(this StorageException exception)
 {
     return(exception.ParseExtendedErrorInformation(
                (errorCode, errorMessage) => errorCode == ExtendedErrorInformationCodes.PropertyValueTooLarge,
                () => false));
 }