using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; namespace PrivaPub.Extensions { public class OperationCancelledExceptionFilter : ExceptionFilterAttribute { readonly Serilog.ILogger Logger; public OperationCancelledExceptionFilter(Serilog.ILogger logger) => Logger = logger.ForContext(); 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); } } }