Advertisement
Guest User

Untitled

a guest
Nov 30th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.12 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. open System
  7.  
  8. type ErrorViewModel(message:string) =
  9.     member __.Message with get() = message
  10.     new() = ErrorViewModel(null)
  11.  
  12. [<Route("error")>]
  13. type ErrorController() =
  14.     inherit ControllerBase()
  15.  
  16.     let unrollException (ex : Exception) =
  17.         let mutable currentException = ex
  18.         while not(isNull(currentException.InnerException)) do
  19.             currentException <- currentException.InnerException
  20.         currentException;
  21.  
  22.     let getExceptionMessage (ex : Exception) =
  23.         let lastException = unrollException(ex)
  24.         lastException.Message
  25.        
  26.  
  27.     [<AllowAnonymous>]
  28.     member this.Index() =
  29.         let feature = this.HttpContext.Features.Get<IExceptionHandlerFeature>()
  30.         let errorViewModel =
  31.             if not(isNull(feature)) && not(isNull(feature.Error))
  32.                 then ErrorViewModel(getExceptionMessage(feature.Error))
  33.             else ErrorViewModel()
  34.         this.BadRequest(errorViewModel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement