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 unrollException (ex : Exception) =
- let mutable currentException = ex
- while not(isNull(currentException.InnerException)) do
- currentException <- currentException.InnerException
- currentException;
- let getExceptionMessage (ex : Exception) =
- let lastException = unrollException(ex)
- lastException.Message
- [<AllowAnonymous>]
- member this.Index() =
- let feature = this.HttpContext.Features.Get<IExceptionHandlerFeature>()
- let errorViewModel =
- if not(isNull(feature)) && not(isNull(feature.Error))
- then ErrorViewModel(getExceptionMessage(feature.Error))
- else ErrorViewModel()
- this.BadRequest(errorViewModel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement