Skip to content

Instantly share code, notes, and snippets.

@Szer
Created December 11, 2018 15:13
Show Gist options
  • Select an option

  • Save Szer/6b2519c6fb6efc80b70a9cd7f3d427b3 to your computer and use it in GitHub Desktop.

Select an option

Save Szer/6b2519c6fb6efc80b70a9cd7f3d427b3 to your computer and use it in GitHub Desktop.
module Infrastructure.Web.Api.Mvc
open Microsoft.AspNetCore.Mvc.Filters
open Microsoft.Extensions.Logging
open Infrastructure.Web.Api.Localization
open System
open Microsoft.AspNetCore.Mvc
let (|NotNull|) name = function
| null -> nullArg name
| o -> o
let inline is<'a> a =
match box a with
| :? 'a as a -> Some a
| _ -> None
type OperationCanceledExceptionFilter(logger) =
inherit ExceptionFilterAttribute(logger)
let (NotNull "logger" logger) = logger
override this.OnException (context : ExceptionContext) =
is<OperationCanceledException> context
|> Option.iter (fun _ ->
this.logger.LogInformation(Resources.RequestWasCancelled)
context.ExceptionHandled <- true
context.Result <- StatusCodeResult(499))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment