Exemplo n.º 1
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();
            }));
        }