Quellcode durchsuchen

递归查找TimedOut异常

老九 vor 3 Jahren
Ursprung
Commit
1770955d33
1 geänderte Dateien mit 16 neuen und 3 gelöschten Zeilen
  1. 16 3
      FastGithub.Http/HttpClientHandler.cs

+ 16 - 3
FastGithub.Http/HttpClientHandler.cs

@@ -126,9 +126,7 @@ namespace FastGithub.Http
         /// <param name="exception"></param>
         private void InterceptRequestException(HttpRequestMessage request, HttpRequestException exception)
         {
-            if (request.RequestUri == null ||
-                exception.InnerException is not SocketException socketException ||
-                socketException.SocketErrorCode != SocketError.TimedOut)
+            if (request.RequestUri == null || IsTimedOutSocketError(exception) == false)
             {
                 return;
             }
@@ -142,6 +140,21 @@ namespace FastGithub.Http
             {
                 this.domainResolver.FlushDomain(new DnsEndPoint(request.Headers.Host, request.RequestUri.Port));
             }
+
+
+            static bool IsTimedOutSocketError(HttpRequestException exception)
+            {
+                var inner = exception.InnerException;
+                while (inner != null)
+                {
+                    if (inner is SocketException socketException && socketException.SocketErrorCode == SocketError.TimedOut)
+                    {
+                        return true;
+                    }
+                    inner = inner.InnerException;
+                }
+                return false;
+            }
         }
 
         /// <summary>