Giraffe: How to return ProblemDetails?

Created on 10 Feb 2020  路  2Comments  路  Source: giraffe-fsharp/Giraffe

ASP.NET Core provides a ProblemDetails type that can be returned in an ActionResult<'T>. What's the advised way of returning a result via Giraffe using this type? Can this be returned directly using Giraffe's json function? cc @ditadi

question

Most helpful comment

Hi, the ProblemDetails is an MVC specific type indeed. However, there's nothing stopping you from creating your own record type and return problem details objects via Giraffe. If you want to couple it with exception handling then you can put this into the Giraffe error handler or you can use an existing ASP.NET Core middleware which already does that for you when you set it up for your custom exception messages, e.g.: https://lurumad.github.io/problem-details-an-standard-way-for-specifying-errors-in-http-api-responses-asp.net-core

All 2 comments

Hi @panesofglass, I do not think it is actually core platform but MVC with provides ProblemDetails type, if that is the case it would be outside scope of Giraffe.

Hi, the ProblemDetails is an MVC specific type indeed. However, there's nothing stopping you from creating your own record type and return problem details objects via Giraffe. If you want to couple it with exception handling then you can put this into the Giraffe error handler or you can use an existing ASP.NET Core middleware which already does that for you when you set it up for your custom exception messages, e.g.: https://lurumad.github.io/problem-details-an-standard-way-for-specifying-errors-in-http-api-responses-asp.net-core

Was this page helpful?
0 / 5 - 0 ratings