SocialPub/PrivaPub/Extensions/OperationCancelledExceptionFilter.cs

23 lines
676 B
C#
Raw Normal View History

2023-02-18 08:52:17 +01:00

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
2023-02-19 00:43:43 +01:00
namespace PrivaPub.Extensions
2023-02-18 08:52:17 +01:00
{
public class OperationCancelledExceptionFilter : ExceptionFilterAttribute
{
readonly Serilog.ILogger Logger;
public OperationCancelledExceptionFilter(Serilog.ILogger logger) =>
Logger = logger.ForContext<OperationCancelledExceptionFilter>();
public override void OnException(ExceptionContext context)
{
if (context.Exception is not OperationCanceledException) return;
Logger.Information($"Request for {context.HttpContext.Request.Path} was cancelled.");
context.ExceptionHandled = true;
context.Result = new StatusCodeResult(499);
}
}
}