@@ -497,11 +497,15 @@ internal bool IsContainerRegistryUnauthenticated(string containerRegistyUrl, boo
497
497
_cmdletPassedIn . WriteDebug ( $ "Getting anonymous access token from the realm: { url } ") ;
498
498
499
499
// 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 ) ;
501
504
502
505
if ( results == null )
503
506
{
504
507
_cmdletPassedIn . WriteDebug ( "Failed to get access token from the realm. results is null." ) ;
508
+ _cmdletPassedIn . WriteDebug ( $ "ErrorRecord: { errRecordTemp } ") ;
505
509
return false ;
506
510
}
507
511
@@ -993,24 +997,29 @@ internal JObject GetHttpResponseJObjectUsingContentHeaders(string url, HttpMetho
993
997
{
994
998
HttpRequestMessage request = new HttpRequestMessage ( method , url ) ;
995
999
996
- if ( string . IsNullOrEmpty ( content ) )
1000
+ // HTTP GET does not expect a body / content.
1001
+ if ( method != HttpMethod . Get )
997
1002
{
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 ) ;
1003
1003
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 ) ;
1006
1011
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 )
1012
1018
{
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
+ }
1014
1023
}
1015
1024
}
1016
1025
@@ -1720,8 +1729,9 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
1720
1729
List < JToken > allVersionsList = foundTags [ "tags" ] . ToList ( ) ;
1721
1730
1722
1731
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 )
1724
1733
{
1734
+ _cmdletPassedIn . WriteDebug ( "No qualifying packages found for the specified criteria." ) ;
1725
1735
return emptyHashResponses ;
1726
1736
}
1727
1737
@@ -1770,7 +1780,9 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
1770
1780
ErrorCategory . InvalidArgument ,
1771
1781
this ) ;
1772
1782
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
1774
1786
}
1775
1787
1776
1788
_cmdletPassedIn . WriteDebug ( $ "'{ packageName } ' version parsed as '{ pkgVersion } '") ;
0 commit comments