@@ -234,15 +234,19 @@ async ValueTask<TResponse> SendRequestWithProductCheckCore()
234
234
235
235
// Evaluate product check result
236
236
237
- var productCheckSucceeded = response . ApiCallDetails . TryGetHeader ( "x-elastic-product" , out var values ) &&
238
- values . FirstOrDefault ( x => x . Equals ( "Elasticsearch" , StringComparison . Ordinal ) ) is not null ;
237
+ var hasSuccessStatusCode = response . ApiCallDetails . HttpStatusCode is >= 200 and <= 299 ;
238
+ if ( hasSuccessStatusCode )
239
+ {
240
+ var productCheckSucceeded = response . ApiCallDetails . TryGetHeader ( "x-elastic-product" , out var values ) &&
241
+ values . FirstOrDefault ( x => x . Equals ( "Elasticsearch" , StringComparison . Ordinal ) ) is not null ;
239
242
240
- _productCheckStatus = productCheckSucceeded
241
- ? ( int ) ProductCheckStatus . Succeeded
242
- : ( int ) ProductCheckStatus . Failed ;
243
+ _productCheckStatus = productCheckSucceeded
244
+ ? ( int ) ProductCheckStatus . Succeeded
245
+ : ( int ) ProductCheckStatus . Failed ;
243
246
244
- if ( _productCheckStatus == ( int ) ProductCheckStatus . Failed )
245
- throw new UnsupportedProductException ( UnsupportedProductException . InvalidProductError ) ;
247
+ if ( _productCheckStatus == ( int ) ProductCheckStatus . Failed )
248
+ throw new UnsupportedProductException ( UnsupportedProductException . InvalidProductError ) ;
249
+ }
246
250
247
251
if ( request . RequestParameters . RequestConfiguration is null )
248
252
return response ;
@@ -254,6 +258,13 @@ async ValueTask<TResponse> SendRequestWithProductCheckCore()
254
258
else if ( originalHeaders is { Count : > 0 } )
255
259
request . RequestParameters . RequestConfiguration . ResponseHeadersToParse = originalHeaders . Value ;
256
260
261
+ if ( ! hasSuccessStatusCode )
262
+ {
263
+ // The product check is unreliable for non success status codes.
264
+ // We have to re-try on the next request.
265
+ _productCheckStatus = ( int ) ProductCheckStatus . NotChecked ;
266
+ }
267
+
257
268
return response ;
258
269
}
259
270
}
0 commit comments