Exemple #1
0
        public static bool IsProblemTableDoesNotExist(this global::Azure.RequestFailedException exception)
        {
            return(exception.ParseExtendedErrorInformation(
                       (errorCode, message) =>
            {
                if (errorCode == ExtendedErrorInformationCodes.TableNotFound)
                {
                    return true;
                }
                if (errorCode == ExtendedErrorInformationCodes.BlobNotFound)
                {
                    return true;
                }
                return ExtendedErrorCodeNotProvided();
            },
                       () => ExtendedErrorCodeNotProvided()));

            bool ExtendedErrorCodeNotProvided()
            {
                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);
            }
        }
Exemple #2
0
        public static TResult ParseStorageException <TResult>(this global::Azure.RequestFailedException 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();
            }));
        }
Exemple #3
0
        public static bool IsProblemDoesNotExist(this global::Azure.RequestFailedException exception)
        {
            return(exception.ParseExtendedErrorInformation(
                       (errorCode, message) =>
            {
                if (errorCode == ExtendedErrorInformationCodes.TableNotFound)
                {
                    return true;
                }
                if (errorCode == ExtendedErrorInformationCodes.BlobNotFound)
                {
                    return true;
                }
                if (errorCode == ExtendedErrorInformationCodes.Other)
                {
                    if ("ContainerNotFound".Equals(exception.ErrorCode, StringComparison.OrdinalIgnoreCase))
                    {
                        return true;
                    }
                }
                return false;
            },
                       () =>
            {
                if (exception.GetHttpStatusCode() == 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;
            }));
        }
Exemple #4
0
 public static bool IsProblemResourceAlreadyExists(this global::Azure.RequestFailedException exception)
 {
     return(exception.ParseExtendedErrorInformation(
                (errorCode, errorMessage) => errorCode == ExtendedErrorInformationCodes.EntityAlreadyExists,
                () => false));
 }
Exemple #5
0
 public static bool IsProblemPropertyValueTooLarge(this global::Azure.RequestFailedException exception)
 {
     return(exception.ParseExtendedErrorInformation(
                (errorCode, errorMessage) => errorCode == ExtendedErrorInformationCodes.PropertyValueTooLarge,
                () => false));
 }