Created
December 11, 2018 15:13
-
-
Save Szer/6b2519c6fb6efc80b70a9cd7f3d427b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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