Advertisement
Guest User

Untitled

a guest
Dec 1st, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.06 KB | None | 0 0
  1. namespace Cardone.Backoffice.ImageSearch.Controllers
  2.  
  3. open Microsoft.AspNetCore.Mvc
  4. open Microsoft.AspNetCore.Authorization
  5. open Microsoft.AspNetCore.Diagnostics
  6.  
  7. type ErrorViewModel (message : string) =
  8.     member __.Message with get() = message
  9.     new() = ErrorViewModel(null)
  10.  
  11. [<Route("error")>]
  12. type ErrorController() =
  13.     inherit ControllerBase()
  14.  
  15.     let getDeepestExceptionMessage (ex) =
  16.         let rec getDeepestException (ex : exn) =
  17.             match ex.InnerException with
  18.                 | null -> ex
  19.                 | _ -> getDeepestException(ex.InnerException)
  20.         getDeepestException(ex).Message
  21.    
  22.     [<AllowAnonymous>]
  23.     member this.Index() =
  24.         this.HttpContext.Features.Get<IExceptionHandlerFeature>()
  25.             |> Option.ofObj
  26.             |> Option.bind (fun value -> Option.ofObj value.Error)
  27.             |> Option.map (getDeepestExceptionMessage >> ErrorViewModel)
  28.             |> Option.defaultValue (ErrorViewModel "Произошла непредвиденная ошибка")
  29.             |> this.BadRequest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement