@@ -234,15 +234,19 @@ async ValueTask<TResponse> SendRequestWithProductCheckCore()
234234
235235 // Evaluate product check result
236236
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 ;
239242
240- _productCheckStatus = productCheckSucceeded
241- ? ( int ) ProductCheckStatus . Succeeded
242- : ( int ) ProductCheckStatus . Failed ;
243+ _productCheckStatus = productCheckSucceeded
244+ ? ( int ) ProductCheckStatus . Succeeded
245+ : ( int ) ProductCheckStatus . Failed ;
243246
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+ }
246250
247251 if ( request . RequestParameters . RequestConfiguration is null )
248252 return response ;
@@ -254,6 +258,13 @@ async ValueTask<TResponse> SendRequestWithProductCheckCore()
254258 else if ( originalHeaders is { Count : > 0 } )
255259 request . RequestParameters . RequestConfiguration . ResponseHeadersToParse = originalHeaders . Value ;
256260
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+
257268 return response ;
258269 }
259270 }
0 commit comments