You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
servant don't treat Nothing as 404 but return null
curl -H 'Content-type: application/json' localhost:3000/user/Alice
< HTTP/1.1 200 OK
< Transfer-Encoding: chunked
< Date: Sat, 03 Mar 2018 16:02:32 GMT
< Server: Warp/3.2.13
< Content-Type: application/json;charset=utf-8
<
* Connection #0 to host localhost left intact
null%
Is it possible to create general handlers for Maybe, now I have to manually throw ServantErrors.
It would be good if servant translate Nothing into 404.
The text was updated successfully, but these errors were encountered:
I see the point you're making, but the response type advertised after the verb (Maybe User in your example) is supposed to be whatever the handler will return in the successful case, that is if we don't encounter any error. The way to achieve what you want with servant is to indeed throw an error. Usually I do this by using a custom monad which contains ExceptT ApplicationError in the stack, where ApplicationError is something like:
and I then convert values of that type to HTTP error responses (ServantErr values) using hoistServer.
Another way to achieve what you want would be to use servant-checked-exceptions. In both cases though, the library requires you to say Get '[JSON] User and drop the Maybe.
Note that this would all become a little more explicit and symmetric once we get around to executing #841.
When I have API defined like:
servant don't treat Nothing as 404 but return null
Is it possible to create general handlers for Maybe, now I have to manually throw ServantErrors.
It would be good if servant translate Nothing into 404.
The text was updated successfully, but these errors were encountered: