Skip to content

Commit

Permalink
chore: additional request error details
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpop-zengenti committed Apr 30, 2024
1 parent 02fd3ec commit d79417f
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,24 @@ public async Task<EndpointResponse> Invoke(
return endpointResponse;
}

using (_logger.BeginScope(
new
{
requestContext = JsonSerializer.Serialize(_requestContext),
routeInfo = JsonSerializer.Serialize(routeInfo)
}))
var responseContent = "";
if (endpointResponse.StatusCode >= 500 &&
endpointResponse.StreamContent is { Length: > 0 } and MemoryStream stream)
{
stream.Position = 0;
using var reader = new StreamReader(stream);
responseContent = await reader.ReadToEndAsync();
}

var state = new
{
requestContext = JsonSerializer.Serialize(_requestContext),
routeInfo = JsonSerializer.Serialize(routeInfo),
responseHeaders = JsonSerializer.Serialize(endpointResponse.Headers),
responseContent
};

using (_logger.BeginScope(state))
{
_logger.LogWarning(
"Invoking endpoint {AbsoluteUri} was not successful: {StatusCode}",
Expand Down

0 comments on commit d79417f

Please sign in to comment.