Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.98 KB | None | 0 0
  1. namespace Infrastructure.Web.Api.Mvc
  2. open Microsoft.AspNetCore.Mvc.Filters
  3. open Microsoft.Extensions.Logging
  4. open Infrastructure.Web.Api.Localization
  5. open System
  6. open Microsoft.AspNetCore.Mvc
  7.  
  8. type OperationCanceledExceptionFilter=
  9.     inherit ExceptionFilterAttribute
  10.         val private internalLogger : ILogger<OperationCanceledExceptionFilter>
  11.         new (logger : ILogger<OperationCanceledExceptionFilter>) =
  12.             {
  13.                
  14.                 inherit ExceptionFilterAttribute()
  15.                 if isNull(logger) then nullArg("logger")
  16.                 internalLogger = logger
  17.             }
  18.    
  19.     override this.OnException (context : ExceptionContext) =
  20.         match context.Exception with
  21.         | :? OperationCanceledException ->
  22.             this.internalLogger.LogInformation(Resources.RequestWasCancelled)
  23.             context.ExceptionHandled <- true
  24.             context.Result <- StatusCodeResult(499)
  25.             ()
  26.         | _ -> ()
  27.         ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement