From 35e6e1e904156720c518594c7105c5e5c6d99403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E7=8C=AB=E8=B7=83?= <1043137532@qq.com> Date: Thu, 21 May 2026 00:24:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E4=BA=8E=E7=89=B9=E5=AE=9A=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E4=BC=9A=E5=B0=9D=E8=AF=95=E6=98=BE=E7=A4=BA=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shared/Extensions/ExceptionExtensions.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Shared/Extensions/ExceptionExtensions.cs b/Shared/Extensions/ExceptionExtensions.cs index 8002d26..78f2d79 100644 --- a/Shared/Extensions/ExceptionExtensions.cs +++ b/Shared/Extensions/ExceptionExtensions.cs @@ -39,16 +39,21 @@ public static class ExceptionExtensions { // 提取堆栈信息 var lines = new List(); bool isInnerException = false; + static string getExceptionMessage(Exception e) => e.Message + (e switch { + WebException webEx => $" (Status={webEx.Status})", + SocketException socketEx => $" (SocketErrorCode={socketEx.SocketErrorCode})", + _ => "" + }); foreach (var currentEx in ex.Flatten()) { if (showMultilineStacks) { - lines.Add((isInnerException ? "→ " : "") + currentEx.Message.ReplaceLineEndings("\r\n", true)); + lines.Add((isInnerException ? "→ " : "") + getExceptionMessage(currentEx).ReplaceLineEndings("\r\n", true)); var stackLines = (currentEx.StackTrace?.SplitLines(true) ?? []) .Select(l => l.BeforeLast("(") + l.AfterLast(")")) .Distinct(); lines.AddRange(stackLines); if (currentEx.GetType() != typeof(Exception)) lines.Add(" 错误类型:" + currentEx.GetType().FullName); } else { - lines.Add(currentEx.Message.ReplaceLineEndings(" ", true)); + lines.Add(getExceptionMessage(currentEx).ReplaceLineEndings(" ", true)); } isInnerException = true; } @@ -104,7 +109,7 @@ public static class ExceptionExtensions { } if (webEx.Status is WebExceptionStatus.NameResolutionFailure or WebExceptionStatus.ConnectFailure or WebExceptionStatus.ReceiveFailure or WebExceptionStatus.SendFailure or WebExceptionStatus.ConnectionClosed or WebExceptionStatus.KeepAliveFailure or WebExceptionStatus.Timeout or - WebExceptionStatus.ProxyNameResolutionFailure) return true; + WebExceptionStatus.ProxyNameResolutionFailure or WebExceptionStatus.SecureChannelFailure) return true; } else if (currentEx is SocketException socketEx) { if (socketEx.SocketErrorCode is SocketError.NetworkDown or SocketError.NetworkUnreachable or SocketError.NetworkReset or SocketError.ConnectionAborted or SocketError.ConnectionReset or SocketError.TimedOut or SocketError.ConnectionRefused or SocketError.HostUnreachable or