@@ -493,11 +493,15 @@ internal bool IsContainerRegistryUnauthenticated(string containerRegistyUrl, boo
493
493
string url = needCatalogAccess ? String . Format ( authUrlTemplate , realm , service , catalogScope ) : String . Format ( authUrlTemplate , realm , service , defaultScope ) ;
494
494
495
495
// 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 ) ;
497
500
498
501
if ( results == null )
499
502
{
500
503
_cmdletPassedIn . WriteDebug ( "Failed to get access token from the realm. results is null." ) ;
504
+ _cmdletPassedIn . WriteDebug ( $ "ErrorRecord: { errRecordTemp } ") ;
501
505
return false ;
502
506
}
503
507
@@ -989,24 +993,29 @@ internal JObject GetHttpResponseJObjectUsingContentHeaders(string url, HttpMetho
989
993
{
990
994
HttpRequestMessage request = new HttpRequestMessage ( method , url ) ;
991
995
992
- if ( string . IsNullOrEmpty ( content ) )
996
+ // HTTP GET does not expect a body / content.
997
+ if ( method != HttpMethod . Get )
993
998
{
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 ) ;
999
999
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 ) ;
1002
1007
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 )
1008
1014
{
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
+ }
1010
1019
}
1011
1020
}
1012
1021
@@ -1716,8 +1725,9 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
1716
1725
List < JToken > allVersionsList = foundTags [ "tags" ] . ToList ( ) ;
1717
1726
1718
1727
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 )
1720
1729
{
1730
+ _cmdletPassedIn . WriteDebug ( "No qualifying packages found for the specified criteria." ) ;
1721
1731
return emptyHashResponses ;
1722
1732
}
1723
1733
@@ -1766,7 +1776,9 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
1766
1776
ErrorCategory . InvalidArgument ,
1767
1777
this ) ;
1768
1778
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
1770
1782
}
1771
1783
1772
1784
_cmdletPassedIn . WriteDebug ( $ "'{ packageName } ' version parsed as '{ pkgVersion } '") ;
0 commit comments