refactor: use Flatten in GetDisplay and IsBadNetwork to support AggregateException
Agent-Logs-Url: https://github.com/Meloong-Git/MeloongCore/sessions/e67129f9-62f2-41e0-82d3-019771a8e525 Co-authored-by: LTCatt <40348278+LTCatt@users.noreply.github.com>
This commit is contained in:
1 parent
49c2a9c8ff
commit
983ae1af11
1 file changed
+2
-2
@@ -39,7 +39,7 @@ public static class ExceptionExtensions {
|
|||||||
// 提取堆栈信息
|
// 提取堆栈信息
|
||||||
var lines = new List<string>();
|
var lines = new List<string>();
|
||||||
bool isInnerException = false;
|
bool isInnerException = false;
|
||||||
for (Exception? currentEx = ex; currentEx is not null; currentEx = currentEx.InnerException) {
|
foreach (var currentEx in ex.Flatten()) {
|
||||||
if (showMultilineStacks) {
|
if (showMultilineStacks) {
|
||||||
lines.Add((isInnerException ? "→ " : "") + currentEx.Message.ReplaceLineEndings("\r\n", true));
|
lines.Add((isInnerException ? "→ " : "") + currentEx.Message.ReplaceLineEndings("\r\n", true));
|
||||||
if (currentEx.GetType() != typeof(Exception)) lines.Add(" 错误类型:" + currentEx.GetType().FullName);
|
if (currentEx.GetType() != typeof(Exception)) lines.Add(" 错误类型:" + currentEx.GetType().FullName);
|
||||||
@@ -89,7 +89,7 @@ public static class ExceptionExtensions {
|
|||||||
/// 判断该异常是否是由于网络连接不良导致。
|
/// 判断该异常是否是由于网络连接不良导致。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool IsBadNetwork(this Exception ex) {
|
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) {
|
if (currentEx is TimeoutException) {
|
||||||
return true;
|
return true;
|
||||||
} else if (currentEx is TaskCanceledException) {
|
} else if (currentEx is TaskCanceledException) {
|
||||||
|
|||||||
Reference in new issue
Block a user