@@ -493,11 +493,15 @@ internal bool IsContainerRegistryUnauthenticated(string containerRegistyUrl, boo
493493 string url = needCatalogAccess ? String . Format ( authUrlTemplate , realm , service , catalogScope ) : String . Format ( authUrlTemplate , realm , service , defaultScope ) ;
494494
495495 // we dont check the errorrecord here because we want to return false if we get a 401 and not throw an error
496- var results = GetHttpResponseJObjectUsingContentHeaders ( url , HttpMethod . Get , content , contentHeaders , out _ ) ;
496+ _cmdletPassedIn . WriteDebug ( $ "Getting anonymous access token from the realm: { url } ") ;
497+ ErrorRecord errRecordTemp = null ;
498+
499+ var results = GetHttpResponseJObjectUsingContentHeaders ( url , HttpMethod . Get , content , contentHeaders , out errRecordTemp ) ;
497500
498501 if ( results == null )
499502 {
500503 _cmdletPassedIn . WriteDebug ( "Failed to get access token from the realm. results is null." ) ;
504+ _cmdletPassedIn . WriteDebug ( $ "ErrorRecord: { errRecordTemp } ") ;
501505 return false ;
502506 }
503507
@@ -989,24 +993,29 @@ internal JObject GetHttpResponseJObjectUsingContentHeaders(string url, HttpMetho
989993 {
990994 HttpRequestMessage request = new HttpRequestMessage ( method , url ) ;
991995
992- if ( string . IsNullOrEmpty ( content ) )
996+ // HTTP GET does not expect a body / content.
997+ if ( method != HttpMethod . Get )
993998 {
994- errRecord = new ErrorRecord (
995- exception : new ArgumentNullException ( $ "Content is null or empty and cannot be used to make a request as its content headers.") ,
996- "RequestContentHeadersNullOrEmpty" ,
997- ErrorCategory . InvalidData ,
998- _cmdletPassedIn ) ;
999999
1000- return null ;
1001- }
1000+ if ( string . IsNullOrEmpty ( content ) )
1001+ {
1002+ errRecord = new ErrorRecord (
1003+ exception : new ArgumentNullException ( $ "Content is null or empty and cannot be used to make a request as its content headers.") ,
1004+ "RequestContentHeadersNullOrEmpty" ,
1005+ ErrorCategory . InvalidData ,
1006+ _cmdletPassedIn ) ;
10021007
1003- request . Content = new StringContent ( content ) ;
1004- request . Content . Headers . Clear ( ) ;
1005- if ( contentHeaders != null )
1006- {
1007- foreach ( var header in contentHeaders )
1008+ return null ;
1009+ }
1010+
1011+ request . Content = new StringContent ( content ) ;
1012+ request . Content . Headers . Clear ( ) ;
1013+ if ( contentHeaders != null )
10081014 {
1009- request . Content . Headers . Add ( header . Key , header . Value ) ;
1015+ foreach ( var header in contentHeaders )
1016+ {
1017+ request . Content . Headers . Add ( header . Key , header . Value ) ;
1018+ }
10101019 }
10111020 }
10121021
@@ -1716,8 +1725,9 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
17161725 List < JToken > allVersionsList = foundTags [ "tags" ] . ToList ( ) ;
17171726
17181727 SortedDictionary < NuGet . Versioning . SemanticVersion , string > sortedQualifyingPkgs = GetPackagesWithRequiredVersion ( allVersionsList , versionType , versionRange , requiredVersion , packageNameForFind , includePrerelease , out errRecord ) ;
1719- if ( errRecord != null )
1728+ if ( errRecord != null && sortedQualifyingPkgs ? . Count == 0 )
17201729 {
1730+ _cmdletPassedIn . WriteDebug ( "No qualifying packages found for the specified criteria." ) ;
17211731 return emptyHashResponses ;
17221732 }
17231733
@@ -1766,7 +1776,9 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
17661776 ErrorCategory . InvalidArgument ,
17671777 this ) ;
17681778
1769- return null ;
1779+ _cmdletPassedIn . WriteError ( errRecord ) ;
1780+ _cmdletPassedIn . WriteDebug ( $ "Skipping package '{ packageName } ' with version '{ pkgVersionString } ' as it is not a valid NuGet version.") ;
1781+ continue ; // skip this version and continue with the next one
17701782 }
17711783
17721784 _cmdletPassedIn . WriteDebug ( $ "'{ packageName } ' version parsed as '{ pkgVersion } '") ;
0 commit comments