haskell-servant / haskell-servant/servant
Capture errors are not returned in the response
- Dominant language
- Haskell
- Stars
- 2k
- Forks
- 427
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 5
Description
I have a very simple server, the full code of which is below:
```Haskell
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
module Main where
import Network.Wai.Handler.Warp
import Servant
import Servant.API
data OneOrZero = One | Zero deriving (Eq, Show)
instance FromHttpApiData OneOrZero where
parseUrlPiece t
| t == "1" = Right One
| t == "0" = Right Zero
| otherwise = Left "field must be 1 or 0"
type API = Capture "v" OneOrZero :> Get '[PlainText] String
app :: Application
app = serve (Proxy :: Proxy API) getEndpoint
getEndpoint :: OneOrZero -> Handler String
getEndpoint _ = pure "Done"
main :: IO ()
main = run 4000 app
```
If I call the server with the path `/0` or `/1`, I get `"Done"` in the response body, as expected. If I use any other path, I get a 400 Bad Request with an empty body—I'm expecting the body to be `field must be 1 or 0`.
What am I doing wrong?
Contributor guide
Assessment
This issue has not been assessed yet.