Skip to content

Instantly share code, notes, and snippets.

@codedmart
Created May 5, 2015 11:54
Show Gist options
  • Select an option

  • Save codedmart/7b3c02960b2d890c9e29 to your computer and use it in GitHub Desktop.

Select an option

Save codedmart/7b3c02960b2d890c9e29 to your computer and use it in GitHub Desktop.
context "client correctly handles error status codes" $ do
let test :: (WrappedApi, String) -> Spec
test (WrappedApi api, desc) =
it desc $
withWaiDaemon (return (serve api (left (500, "error message")))) $
\ host -> do
let getResponse :: EitherT ServantError IO ()
getResponse = client api host
Left FailureResponse{..} <- liftIO $ runEitherT getResponse
runIO $ responseStatus `shouldBe` (Status 500 "error message")
mapM_ test $
(WrappedApi (Proxy :: Proxy Delete), "Delete") :
(WrappedApi (Proxy :: Proxy (Get '[JSON] ())), "Get") :
(WrappedApi (Proxy :: Proxy (Post '[JSON] ())), "Post") :
(WrappedApi (Proxy :: Proxy (Put '[JSON] ())), "Put") :
[]
test/Servant/ClientSpec.hs:4:11:
Could not deduce (Arg Spec ~ ())
from the context (HasServer (Canonicalize api),
Server api ~ EitherT (Int, String) IO a,
HasClient (Canonicalize api),
Client api ~ EitherT ServantError IO ())
bound by a pattern with constructor
WrappedApi :: forall api a.
(HasServer (Canonicalize api),
Server api ~ EitherT (Int, String) IO a,
HasClient (Canonicalize api),
Client api ~ EitherT ServantError IO ()) =>
Proxy api -> WrappedApi,
in an equation for ‘test’
at test/Servant/ClientSpec.hs:246:15-28
Expected type: Spec
Actual type: SpecWith (Arg Spec)
In the expression:
it desc
$ withWaiDaemon (return (serve api (left (500, "error message"))))
$ \ host
-> do { let ...;
Left (FailureResponse {..}) <- liftIO $ runEitherT getResponse;
.... }
In an equation for ‘test’:
test (WrappedApi api, desc)
= it desc
$ withWaiDaemon (return (serve api (left (500, "error message"))))
$ \ host
-> do { let ...;
.... }
In the second argument of ‘($)’, namely
‘do { let test :: (WrappedApi, String) -> Spec
test (WrappedApi api, desc)
= it desc $ withWaiDaemon (return (serve api (left ...))) $ ...;
mapM_ test
$ (WrappedApi (Proxy :: Proxy Delete), "Delete")
: (WrappedApi (Proxy :: Proxy (Get '[JSON] ())), "Get")
: (WrappedApi (Proxy :: Proxy (Post '[JSON] ())), "Post")
: (WrappedApi (Proxy :: Proxy (Put '[JSON] ())), "Put") : [] }’
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment