递归查找TimedOut异常

This commit is contained in:
老九 2021-09-19 14:21:29 +08:00
parent c066e153be
commit 1770955d33

View File

@ -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>