Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Cardone.Backoffice.ImageSearch.Controllers
- open Microsoft.AspNetCore.Mvc
- open Microsoft.AspNetCore.Authorization
- open Microsoft.AspNetCore.Diagnostics
- open System
- type ErrorViewModel (message : string) =
- member __.Message with get() = message
- new() = ErrorViewModel(null)
- [<Route("error")>]
- type ErrorController() =
- inherit ControllerBase()
- let getDeepestExceptionMessage (ex : Exception) =
- let rec getDeepestException (ex : exn) =
- match ex.InnerException with
- | null -> ex
- | _ -> getDeepestException(ex.InnerException)
- getDeepestException(ex).Message
- [<AllowAnonymous>]
- member this.Index() =
- let ex =
- match this.HttpContext.Features.Get<IExceptionHandlerFeature>() with
- | null -> None
- | value when (not << isNull) value.Error -> Some value.Error
- | _ -> None
- let errorViewModel =
- ex
- |> Option.map (getDeepestExceptionMessage >> ErrorViewModel)
- |> Option.defaultValue (ErrorViewModel("Произошла непредвиденная ошибка"))
- this.BadRequest(errorViewModel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement