Skip to content

Commit

Permalink
Add override SendAsync with HttpResponseMessage (#22)
Browse files Browse the repository at this point in the history
SendAsync override for ConsulMetricsHttpClientWrapper.cs
---------

Co-authored-by: Швед Дмитрий <[email protected]>
  • Loading branch information
muphblu and Швед Дмитрий authored Nov 21, 2023
1 parent 294c363 commit 923bd19
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ATI.Services.Consul/ATI.Services.Consul.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="atisu.services.common" Version="12.3.0" />
<PackageReference Include="atisu.services.common" Version="13.2.1" />
<PackageReference Include="Consul" Version="1.6.10.9" />
</ItemGroup>
</Project>
31 changes: 31 additions & 0 deletions ATI.Services.Consul/ConsulMetricsHttpClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,37 @@ public Task<OperationResult<string>> PatchAsync(

#endregion

#region Send

public async Task<OperationResult<HttpResponseMessage<TResponse>>> SendAsync<TBody, TResponse>(
HttpMethod methodName,
string url,
TBody body,
string metricName,
Dictionary<string, string> headers = null,
string urlTemplate = null,
string[] additionalLabels = null)
{
using var _ =
_metricsTracingFactory.CreateLoggingMetricsTimer(metricName,
$"{methodName}:{urlTemplate ?? url}",
additionalLabels);
{
try
{
var serviceAddress = await _serviceAddress.ToHttpAsync();
return await _clientWrapper.SendAsync<TBody, TResponse>(new Uri(new Uri(serviceAddress),url), metricName, body, headers, methodName);
}
catch (Exception e)
{
_logger.LogWithObject(_serviceOptions.LogLevelOverride(LogLevel.Error), e);
return new(ActionStatus.InternalServerError);
}
}
}

#endregion

private async Task<OperationResult<T>> SendAsync<T>(string url,
string urlTemplate,
string metricName,
Expand Down

0 comments on commit 923bd19

Please sign in to comment.