@@ -623,15 +623,9 @@ private void TryChangeProjectFile(DirectoryInfo projectDir, Regex pattern, strin
623623 }
624624 }
625625
626- private static async Task ExecuteGetRequest ( string address , HttpClient httpClient , CancellationToken cancellationToken )
626+ private static async Task < HttpResponseMessage > ExecuteGetRequest ( string address , HttpClient httpClient , CancellationToken cancellationToken )
627627 {
628- using var stream = await httpClient . GetStreamAsync ( address , cancellationToken ) ;
629- var buffer = new byte [ 1024 ] ;
630- int bytesRead ;
631- while ( ( bytesRead = stream . Read ( buffer , 0 , buffer . Length ) ) > 0 )
632- {
633- // do nothing
634- }
628+ return await httpClient . GetAsync ( address , cancellationToken ) ;
635629 }
636630
637631 private bool IsFeedReachable ( string feed , int timeoutMilliSeconds , int tryCount , bool allowExceptions = true )
@@ -673,7 +667,8 @@ private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount,
673667 cts . CancelAfter ( timeoutMilliSeconds ) ;
674668 try
675669 {
676- ExecuteGetRequest ( feed , client , cts . Token ) . GetAwaiter ( ) . GetResult ( ) ;
670+ var response = ExecuteGetRequest ( feed , client , cts . Token ) . GetAwaiter ( ) . GetResult ( ) ;
671+ response . EnsureSuccessStatusCode ( ) ;
677672 logger . LogInfo ( $ "Querying NuGet feed '{ feed } ' succeeded.") ;
678673 return true ;
679674 }
@@ -687,6 +682,13 @@ private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount,
687682 timeoutMilliSeconds *= 2 ;
688683 continue ;
689684 }
685+ if ( exc is HttpRequestException hre &&
686+ hre . StatusCode == HttpStatusCode . Unauthorized )
687+ {
688+
689+ logger . LogInfo ( $ "Received 401 Unauthorized error from NuGet feed '{ feed } '.") ;
690+ return false ;
691+ }
690692
691693 // We're only interested in timeouts.
692694 var start = allowExceptions ? "Considering" : "Not considering" ;
0 commit comments