cdepillabout / cdepillabout/servant-checked-exceptions
servant-client doesn't return envelopes for non-2xx status codes
- Dominant language
- Haskell
- Stars
- 75
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
Full reproduction: https://github.com/bergmark/sce
Using servant-0.13.1 and servant-checked-exceptions-2.0.0.0
```haskell
data BadReq = BadReq deriving Show
deriveJSON defaultOptions ''BadReq
instance ErrStatus BadReq where toErrStatus BadReq = badRequest400
type API = Throws BadReq :> Get '[JSON] Value
api :: Proxy API
api = Proxy
server :: Server API
server = pureErrEnvelope BadReq
main :: IO ()
main = do
tid <- forkIO (run 8080 $ serve api server)
manager' <- newManager defaultManagerSettings
print =<< runClientM (client api) (mkClientEnv manager' (BaseUrl Http "localhost" 8080 ""))
killThread tid
```
I expected this to print the Error envelope but instead I get
```haskell
Left (FailureResponse (Response {responseStatusCode = Status {statusCode = 400, statusMessage = "Bad Request"}, responseHeaders = fromList [("Transfer-Encoding","chunked"),("Date","Sun, 15 Jul 2018 17:53:24 GMT"),("Server","Warp/3.2.22"),("Content-Type","application/json;charset=utf-8")], responseHttpVersion = HTTP/1.1, responseBody = "{\"err\":[]}"}))
```
If i change the ErrStatus instance to return `ok200` I get the envelope as expected:
```haskell
Right (ErrEnvelope (Identity BadReq))
```
Is there something I'm missing?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.