Procházet zdrojové kódy

Merge pull request #7 from Meloong-Git/copilot/refactor-exception-extensions

refactor: support AggregateException in GetDisplay and IsBadNetwork via Flatten
龙腾猫跃 před 5 měsíci
rodič
revize
be6336f548
1 změnil soubory, kde provedl 2 přidání a 2 odebrání
  1. 2 2
      Shared/Extensions/ExceptionExtensions.cs

+ 2 - 2
Shared/Extensions/ExceptionExtensions.cs

@@ -39,7 +39,7 @@ public static class ExceptionExtensions {
         // 提取堆栈信息
         var lines = new List<string>();
         bool isInnerException = false;
-        for (Exception? currentEx = ex; currentEx is not null; currentEx = currentEx.InnerException) {
+        foreach (var currentEx in ex.Flatten()) {
             if (showMultilineStacks) {
                 lines.Add((isInnerException ? "→ " : "") + currentEx.Message.ReplaceLineEndings("\r\n", true));
                 if (currentEx.GetType() != typeof(Exception)) lines.Add("   错误类型:" + currentEx.GetType().FullName);
@@ -89,7 +89,7 @@ public static class ExceptionExtensions {
     /// 判断该异常是否是由于网络连接不良导致。
     /// </summary>
     public static bool IsBadNetwork(this Exception ex) {
-        for (Exception? currentEx = ex; currentEx is not null; currentEx = currentEx.InnerException) {
+        foreach (var currentEx in ex.Flatten()) {
             if (currentEx is TimeoutException) {
                 return true;
             } else if (currentEx is TaskCanceledException) {