in src/Elastic.Transport/Components/Pipeline/RequestPipeline.cs [153:196]
public TResponse CallProductEndpoint<TResponse>(Endpoint endpoint, BoundConfiguration boundConfiguration, PostData? postData, Auditor? auditor)
where TResponse : TransportResponse, new()
=> CallProductEndpointCoreAsync<TResponse>(false, endpoint, boundConfiguration, postData, auditor).EnsureCompleted();
/// Call the product's API endpoint ensuring rich enough exceptions are thrown
public Task<TResponse> CallProductEndpointAsync<TResponse>(Endpoint endpoint, BoundConfiguration boundConfiguration, PostData? postData, Auditor? auditor, CancellationToken cancellationToken = default)
where TResponse : TransportResponse, new()
=> CallProductEndpointCoreAsync<TResponse>(true, endpoint, boundConfiguration, postData, auditor, cancellationToken).AsTask();
private async ValueTask<TResponse> CallProductEndpointCoreAsync<TResponse>(
bool isAsync, Endpoint endpoint, BoundConfiguration boundConfiguration, PostData? postData, Auditor? auditor, CancellationToken cancellationToken = default)
where TResponse : TransportResponse, new()
{
using var audit = auditor?.Add(HealthyResponse, _dateTimeProvider, endpoint.Node);
try
{
TResponse response;
if (isAsync)
response = await _requestInvoker.RequestAsync<TResponse>(endpoint, boundConfiguration, postData, cancellationToken).ConfigureAwait(false);
else
response = _requestInvoker.Request<TResponse>(endpoint, boundConfiguration, postData);
response.ApiCallDetails.AuditTrail = auditor;
ThrowBadAuthPipelineExceptionWhenNeeded(response.ApiCallDetails, response);
if (!response.ApiCallDetails.HasSuccessfulStatusCodeAndExpectedContentType && audit is not null)
{
var @event = response.ApiCallDetails.HttpStatusCode != null ? AuditEvent.BadResponse : BadRequest;
audit.Event = @event;
}
return response;
}
catch (Exception e) when (audit is not null)
{
var @event = e is TransportException t && t.ApiCallDetails.HttpStatusCode != null ? AuditEvent.BadResponse : BadRequest;
audit.Event = @event;
audit.Exception = e;
throw;
}
}