Skip to content

Commit

Permalink
Fixes #91 --ECL (#102)
Browse files Browse the repository at this point in the history
Fix as per PR --ECL
  • Loading branch information
Enkidu93 authored Aug 30, 2023
1 parent 688d83c commit e688077
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Serval.Shared/Controllers/HttpResultFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Diagnostics;

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

public HttpResultFilter(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<HttpResultFilter>();
}

public override Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
if ((context.Result is ObjectResult r) && (r.StatusCode >= 400))
{
_logger.LogInformation($"Responded with code {r.StatusCode}. Trace: {Activity.Current?.Id}");
}
return base.OnResultExecutionAsync(context, next);
}
}
}
1 change: 1 addition & 0 deletions src/Serval.Shared/Controllers/ServalControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[TypeFilter(typeof(OperationCancelledExceptionFilter))]
[TypeFilter(typeof(NotSupportedExceptionFilter))]
[TypeFilter(typeof(ServiceUnavailableException))]
[TypeFilter(typeof(HttpResultFilter))]
public abstract class ServalControllerBase : Controller
{
private readonly IAuthorizationService _authService;
Expand Down

0 comments on commit e688077

Please sign in to comment.