@@ -1135,6 +1135,42 @@ public int GetCountFromResponse(string httpResponse, out ErrorRecord errRecord)
1135
1135
try
1136
1136
{
1137
1137
doc . LoadXml ( httpResponse ) ;
1138
+
1139
+ bool countSearchSucceeded = false ;
1140
+ XmlNodeList elemList = doc . GetElementsByTagName ( "m:count" ) ;
1141
+ if ( elemList . Count > 0 )
1142
+ {
1143
+ countSearchSucceeded = true ;
1144
+ XmlNode node = elemList [ 0 ] ;
1145
+ if ( node == null || String . IsNullOrWhiteSpace ( node . InnerText ) )
1146
+ {
1147
+ countSearchSucceeded = false ;
1148
+ errRecord = new ErrorRecord (
1149
+ new PSArgumentException ( "Count property from server response was empty, invalid or not present." ) ,
1150
+ "GetCountFromResponseFailure" ,
1151
+ ErrorCategory . InvalidData ,
1152
+ this ) ;
1153
+ }
1154
+ else
1155
+ {
1156
+ countSearchSucceeded = int . TryParse ( node . InnerText , out count ) ;
1157
+ }
1158
+ }
1159
+
1160
+ if ( ! countSearchSucceeded )
1161
+ {
1162
+ // Note: not all V2 servers may have the 'count' property implemented or valid (i.e CloudSmith server), in this case try to get 'd:Id' property.
1163
+ elemList = doc . GetElementsByTagName ( "d:Id" ) ;
1164
+ if ( elemList . Count > 0 )
1165
+ {
1166
+ count = elemList . Count ;
1167
+ errRecord = null ;
1168
+ }
1169
+ else
1170
+ {
1171
+ _cmdletPassedIn . WriteDebug ( $ "Property 'count' and 'd:Id' could not be found in response. This may indicate that the package could not be found") ;
1172
+ }
1173
+ }
1138
1174
}
1139
1175
catch ( XmlException e )
1140
1176
{
@@ -1144,17 +1180,6 @@ public int GetCountFromResponse(string httpResponse, out ErrorRecord errRecord)
1144
1180
ErrorCategory . InvalidData ,
1145
1181
this ) ;
1146
1182
}
1147
- if ( errRecord != null )
1148
- {
1149
- return count ;
1150
- }
1151
-
1152
- XmlNodeList elemList = doc . GetElementsByTagName ( "m:count" ) ;
1153
- if ( elemList . Count > 0 )
1154
- {
1155
- XmlNode node = elemList [ 0 ] ;
1156
- count = int . Parse ( node . InnerText ) ;
1157
- }
1158
1183
1159
1184
return count ;
1160
1185
}
0 commit comments