Skip to content

Commit

Permalink
Fixes #214
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Nov 7, 2023
1 parent af79060 commit 7e9f225
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Serval.Shared/Controllers/ErrorResultFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Serval.Shared.Controllers
{
public class ErrorResultFilter : ResultFilterAttribute
public class ErrorResultFilter : IAlwaysRunResultFilter
{
private readonly ILogger _logger;

Expand All @@ -12,15 +12,16 @@ public ErrorResultFilter(ILoggerFactory loggerFactory)
_logger = loggerFactory.CreateLogger<ErrorResultFilter>();
}

public override Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
public void OnResultExecuted(ResultExecutedContext context) { }

public void OnResultExecuting(ResultExecutingContext context)
{
if ((context.Result is ObjectResult r) && (r.StatusCode >= 400))
{
_logger.LogInformation(
$"Client {((Controller)context.Controller).User.Identity?.Name?.ToString()} made request:\n {JsonSerializer.Serialize(((Controller)context.Controller).ControllerContext.RouteData.Values, new JsonSerializerOptions { WriteIndented = true })}.\n Serval responded with code {r.StatusCode}. Trace: {Activity.Current?.Id}"
);
}
return base.OnResultExecutionAsync(context, next);
}
}
}

0 comments on commit 7e9f225

Please sign in to comment.