Skip to content

Commit

Permalink
Do not check product status for non-success responses (#8306) (#8308)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Bernd <[email protected]>
  • Loading branch information
github-actions[bot] and flobernd authored Aug 19, 2024
1 parent 14a5d1b commit 9746515
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,19 @@ async ValueTask<TResponse> SendRequestWithProductCheckCore()

// Evaluate product check result

var productCheckSucceeded = response.ApiCallDetails.TryGetHeader("x-elastic-product", out var values) &&
values.FirstOrDefault(x => x.Equals("Elasticsearch", StringComparison.Ordinal)) is not null;
var hasSuccessStatusCode = response.ApiCallDetails.HttpStatusCode is >= 200 and <= 299;
if (hasSuccessStatusCode)
{
var productCheckSucceeded = response.ApiCallDetails.TryGetHeader("x-elastic-product", out var values) &&
values.FirstOrDefault(x => x.Equals("Elasticsearch", StringComparison.Ordinal)) is not null;

_productCheckStatus = productCheckSucceeded
? (int)ProductCheckStatus.Succeeded
: (int)ProductCheckStatus.Failed;
_productCheckStatus = productCheckSucceeded
? (int)ProductCheckStatus.Succeeded
: (int)ProductCheckStatus.Failed;

if (_productCheckStatus == (int)ProductCheckStatus.Failed)
throw new UnsupportedProductException(UnsupportedProductException.InvalidProductError);
if (_productCheckStatus == (int)ProductCheckStatus.Failed)
throw new UnsupportedProductException(UnsupportedProductException.InvalidProductError);
}

if (request.RequestParameters.RequestConfiguration is null)
return response;
Expand All @@ -254,6 +258,13 @@ async ValueTask<TResponse> SendRequestWithProductCheckCore()
else if (originalHeaders is { Count: > 0 })
request.RequestParameters.RequestConfiguration.ResponseHeadersToParse = originalHeaders.Value;

if (!hasSuccessStatusCode)
{
// The product check is unreliable for non success status codes.
// We have to re-try on the next request.
_productCheckStatus = (int)ProductCheckStatus.NotChecked;
}

return response;
}
}
Expand Down

0 comments on commit 9746515

Please sign in to comment.