Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

servant-client doesn't return envelopes for non-2xx status codes #27

Open
bergmark opened this issue Jul 15, 2018 · 4 comments
Open

servant-client doesn't return envelopes for non-2xx status codes #27

bergmark opened this issue Jul 15, 2018 · 4 comments

Comments

@bergmark
Copy link
Contributor

Full reproduction: https://github.com/bergmark/sce

Using servant-0.13.1 and servant-checked-exceptions-2.0.0.0

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

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:

Right (ErrEnvelope (Identity BadReq))

Is there something I'm missing?

@cdepillabout
Copy link
Owner

I have responded to this here: bergmark/sce#1.

@cdepillabout
Copy link
Owner

This also causes the example to fail:

$ stack exec -- servant-checked-exceptions-example-client foobar
Got a ServantErr: FailureResponse (Response {responseStatusCode = Status {statusCode = 404, statusMessage = "Not Found"}, responseHeaders = fromList [("Transfer-Encoding","chunked"),("Date","Mon, 16 Jul 2018 02:26:30 GMT"),("Server","Warp/3.2.22"),("Content-Type","application/json;charset=utf-8")], responseHttpVersion = HTTP/1.1, responseBody = "{\"err\":\"BadSearchTermErr\"}"})

I think for now, if you want to set exception statuses to something other than http 200, servant-client is not going to work correctly.

I said this on bergmark/sce#1 as well, but if someone wants to create an issue on the servant repo about this, I am willing to do the work to get servant-checked-exceptions fixed.

@bergmark
Copy link
Contributor Author

Thanks a lot for digging into this!

I'll file an issue upstream.

@cdepillabout
Copy link
Owner

This was also reported by @jonathanknowles in #28.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants