From 7e9f2259a99c42a8beee2625bb59b1c1f2b7e241 Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Tue, 7 Nov 2023 12:41:08 -0500 Subject: [PATCH] Fixes #214 --- src/Serval.Shared/Controllers/ErrorResultFilter.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Serval.Shared/Controllers/ErrorResultFilter.cs b/src/Serval.Shared/Controllers/ErrorResultFilter.cs index a928aeb2..46928e8e 100644 --- a/src/Serval.Shared/Controllers/ErrorResultFilter.cs +++ b/src/Serval.Shared/Controllers/ErrorResultFilter.cs @@ -3,7 +3,7 @@ namespace Serval.Shared.Controllers { - public class ErrorResultFilter : ResultFilterAttribute + public class ErrorResultFilter : IAlwaysRunResultFilter { private readonly ILogger _logger; @@ -12,7 +12,9 @@ public ErrorResultFilter(ILoggerFactory loggerFactory) _logger = loggerFactory.CreateLogger(); } - 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)) { @@ -20,7 +22,6 @@ public override Task OnResultExecutionAsync(ResultExecutingContext context, Resu $"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); } } }