public static bool IsRetryableException()

in src/internal/restapi-common/RetryUtilities.cs [33:101]


    public static bool IsRetryableException(this Exception e)
    {
        if (IsTaskCancelledException(e))
        {
            return true;
        }

        if (e is HttpRequestException re && IsRetryableHttpStatusCode(re.StatusCode))
        {
            return true;
        }

        if (e is HttpOperationException he && he.Response != null)
        {
            if (IsRetryableHttpStatusCode(he.Response.StatusCode))
            {
                return true;
            }
        }

        var socketException = FindFirstExceptionOfType<SocketException>(e);
        if (socketException != null &&
            SocketErrorCodes.Contains(socketException.SocketErrorCode))
        {
            return true;
        }

        // Seen Name or service not known error due to DNS resolution failures.
        if (socketException != null &&
            socketException.Message.StartsWith("Name or service not known"))
        {
            return true;
        }

        var webException = FindFirstExceptionOfType<WebException>(e);
        if (webException != null)
        {
            if (WebExceptionStatus.Contains(webException.Status))
            {
                return true;
            }

            if (webException.Status == System.Net.WebExceptionStatus.ProtocolError)
            {
                if (webException.Response is HttpWebResponse response &&
                    IsRetryableHttpStatusCode(response.StatusCode))
                {
                    return true;
                }
            }
        }

        return false;

        static bool IsRetryableHttpStatusCode(HttpStatusCode? code)
        {
            switch (code)
            {
                case HttpStatusCode.InternalServerError:
                case HttpStatusCode.ServiceUnavailable:
                case HttpStatusCode.RequestTimeout:
                case HttpStatusCode.GatewayTimeout:
                case HttpStatusCode.BadGateway:
                    return true;
            }

            return false;
        }
    }