コード例 #1
0
ファイル: Uploader.cs プロジェクト: alshain/ShareX
        private string AddWebError(Exception e, string url)
        {
            string response = null;

            if (Errors != null && e != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Message:");
                sb.AppendLine(e.Message);

                if (!string.IsNullOrEmpty(url))
                {
                    sb.AppendLine();
                    sb.AppendLine("Request URL:");
                    sb.AppendLine(URLHelpers.RemoveQueryString(url));
                }

                if (e is WebException webException)
                {
                    try
                    {
                        HttpWebResponse webResponse = (HttpWebResponse)webException.Response;

                        using (webResponse)
                        {
                            response = ProcessWebResponse(webResponse);

                            if (!string.IsNullOrEmpty(response))
                            {
                                sb.AppendLine();
                                sb.AppendLine("Response:");
                                sb.AppendLine(response);
                            }
                        }
                    }
                    catch (Exception nested)
                    {
                        DebugHelper.WriteException(nested, "AddWebError() WebException handler");
                    }
                }

                sb.AppendLine();
                sb.AppendLine("Stack trace:");
                sb.AppendLine(e.StackTrace);

                string errorText = sb.ToString().Trim();
                Errors.Add(errorText);
                DebugHelper.WriteLine("Error:\r\n" + errorText);
            }

            return(response);
        }