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
- type ErrorViewModel (message : string) =
- member __.Message with get() = message
- new() = ErrorViewModel(null)
- [<Route("error")>]
- type ErrorController() =
- inherit ControllerBase()
- let getDeepestExceptionMessage (ex) =
- let rec getDeepestException (ex : exn) =
- match ex.InnerException with
- | null -> ex
- | _ -> getDeepestException(ex.InnerException)
- getDeepestException(ex).Message
- [<AllowAnonymous>]
- member this.Index() =
- this.HttpContext.Features.Get<IExceptionHandlerFeature>()
- |> Option.ofObj
- |> Option.bind (fun value -> Option.ofObj value.Error)
- |> Option.map (getDeepestExceptionMessage >> ErrorViewModel)
- |> Option.defaultValue (ErrorViewModel "Произошла непредвиденная ошибка")
- |> this.BadRequest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement