I have created a helper function for returning Thoth.Json style json from my Giraffe project that takes a Result<'a,'b> and returns JSON.
let json result next (ctx: HttpContext) =
match result with
| Ok result ->
(setHttpHeader "Content-Type" "application/json" >=>
setBodyFromString (Encode.Auto.toString (0, result))) next ctx
| Error e -> ...
This works fine until I return Ok (), which compiles and should be perfectly valid.
However, Thoth.Json is not so fond of it:
Cannot generate auto encoder for Microsoft.FSharp.Core.Unit. Please pass an extra encoder.
How can I either check if result is a unit or make the auto encoder handle unit ?