@@ -497,11 +497,15 @@ internal bool IsContainerRegistryUnauthenticated(string containerRegistyUrl, boo
497497 _cmdletPassedIn . WriteDebug ( $ "Getting anonymous access token from the realm: { url } ") ;
498498
499499 // we dont check the errorrecord here because we want to return false if we get a 401 and not throw an error
500- var results = GetHttpResponseJObjectUsingContentHeaders ( url , HttpMethod . Get , content , contentHeaders , out _ ) ;
500+ _cmdletPassedIn . WriteDebug ( $ "Getting anonymous access token from the realm: { url } ") ;
501+ ErrorRecord errRecordTemp = null ;
502+
503+ var results = GetHttpResponseJObjectUsingContentHeaders ( url , HttpMethod . Get , content , contentHeaders , out errRecordTemp ) ;
501504
502505 if ( results == null )
503506 {
504507 _cmdletPassedIn . WriteDebug ( "Failed to get access token from the realm. results is null." ) ;
508+ _cmdletPassedIn . WriteDebug ( $ "ErrorRecord: { errRecordTemp } ") ;
505509 return false ;
506510 }
507511
@@ -993,24 +997,29 @@ internal JObject GetHttpResponseJObjectUsingContentHeaders(string url, HttpMetho
993997 {
994998 HttpRequestMessage request = new HttpRequestMessage ( method , url ) ;
995999
996- if ( string . IsNullOrEmpty ( content ) )
1000+ // HTTP GET does not expect a body / content.
1001+ if ( method != HttpMethod . Get )
9971002 {
998- errRecord = new ErrorRecord (
999- exception : new ArgumentNullException ( $ "Content is null or empty and cannot be used to make a request as its content headers.") ,
1000- "RequestContentHeadersNullOrEmpty" ,
1001- ErrorCategory . InvalidData ,
1002- _cmdletPassedIn ) ;
10031003
1004- return null ;
1005- }
1004+ if ( string . IsNullOrEmpty ( content ) )
1005+ {
1006+ errRecord = new ErrorRecord (
1007+ exception : new ArgumentNullException ( $ "Content is null or empty and cannot be used to make a request as its content headers.") ,
1008+ "RequestContentHeadersNullOrEmpty" ,
1009+ ErrorCategory . InvalidData ,
1010+ _cmdletPassedIn ) ;
10061011
1007- request . Content = new StringContent ( content ) ;
1008- request . Content . Headers . Clear ( ) ;
1009- if ( contentHeaders != null )
1010- {
1011- foreach ( var header in contentHeaders )
1012+ return null ;
1013+ }
1014+
1015+ request . Content = new StringContent ( content ) ;
1016+ request . Content . Headers . Clear ( ) ;
1017+ if ( contentHeaders != null )
10121018 {
1013- request . Content . Headers . Add ( header . Key , header . Value ) ;
1019+ foreach ( var header in contentHeaders )
1020+ {
1021+ request . Content . Headers . Add ( header . Key , header . Value ) ;
1022+ }
10141023 }
10151024 }
10161025
@@ -1720,8 +1729,9 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
17201729 List < JToken > allVersionsList = foundTags [ "tags" ] . ToList ( ) ;
17211730
17221731 SortedDictionary < NuGet . Versioning . SemanticVersion , string > sortedQualifyingPkgs = GetPackagesWithRequiredVersion ( allVersionsList , versionType , versionRange , requiredVersion , packageNameForFind , includePrerelease , out errRecord ) ;
1723- if ( errRecord != null )
1732+ if ( errRecord != null && sortedQualifyingPkgs ? . Count == 0 )
17241733 {
1734+ _cmdletPassedIn . WriteDebug ( "No qualifying packages found for the specified criteria." ) ;
17251735 return emptyHashResponses ;
17261736 }
17271737
@@ -1770,7 +1780,9 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
17701780 ErrorCategory . InvalidArgument ,
17711781 this ) ;
17721782
1773- return null ;
1783+ _cmdletPassedIn . WriteError ( errRecord ) ;
1784+ _cmdletPassedIn . WriteDebug ( $ "Skipping package '{ packageName } ' with version '{ pkgVersionString } ' as it is not a valid NuGet version.") ;
1785+ continue ; // skip this version and continue with the next one
17741786 }
17751787
17761788 _cmdletPassedIn . WriteDebug ( $ "'{ packageName } ' version parsed as '{ pkgVersion } '") ;
0 commit comments