From ed7d235b260a6d04a17a417b453e641c063cacea Mon Sep 17 00:00:00 2001 From: Timo von Holtz Date: Mon, 25 May 2015 17:51:35 +1000 Subject: [PATCH 1/2] Don't export HttpException --- servant-client/src/Servant/Common/Req.hs | 19 ++++++++++--------- servant-client/test/Servant/ClientSpec.hs | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/servant-client/src/Servant/Common/Req.hs b/servant-client/src/Servant/Common/Req.hs index b726e7a9..1ff6d1cb 100644 --- a/servant-client/src/Servant/Common/Req.hs +++ b/servant-client/src/Servant/Common/Req.hs @@ -46,13 +46,13 @@ data ServantError { responseContentType :: MediaType , responseBody :: ByteString } - | ConnectionError - { connectionError :: HttpException - } | InvalidContentTypeHeader { responseContentTypeHeader :: ByteString , responseBody :: ByteString } + | ConnectionError + { connectionError :: String + } deriving (Show) data Req = Req @@ -148,11 +148,11 @@ performRequest reqMethod req isWantedStatus reqHost = do } eResponse <- liftIO $ __withGlobalManager $ \ manager -> - catchHttpException $ - Client.httpLbs request manager + catchConnectionError $ + Client.httpLbs request manager case eResponse of Left err -> - left $ ConnectionError err + left $ ConnectionError (show err) Right response -> do let status = Client.responseStatus response @@ -185,6 +185,7 @@ performRequestNoBody reqMethod req wantedStatus reqHost = do _ <- performRequest reqMethod req (`elem` wantedStatus) reqHost return () -catchHttpException :: IO a -> IO (Either HttpException a) -catchHttpException action = - catch (Right <$> action) (pure . Left) +catchConnectionError :: IO a -> IO (Either ServantError a) +catchConnectionError action = + catch (Right <$> action) $ \e -> + pure . Left . ConnectionError . show $ (e :: HttpException) diff --git a/servant-client/test/Servant/ClientSpec.hs b/servant-client/test/Servant/ClientSpec.hs index 12f06a8b..a50f55d4 100644 --- a/servant-client/test/Servant/ClientSpec.hs +++ b/servant-client/test/Servant/ClientSpec.hs @@ -303,7 +303,7 @@ failSpec = withFailServer $ \ baseUrl -> do it "reports ConnectionError" $ do Left res <- runEitherT getGetWrongHost case res of - ConnectionError (C.FailedConnectionException2 "127.0.0.1" 19872 False _) -> return () + ConnectionError _ -> return () _ -> fail $ "expected ConnectionError, but got " <> show res it "reports UnsupportedContentType" $ do From a4bf32c51a484e301faaf68b3cdb5607bbfbf0b6 Mon Sep 17 00:00:00 2001 From: Christian Marie Date: Fri, 12 Jun 2015 21:13:22 +1000 Subject: [PATCH 2/2] servant-client: Hide HttpException by wrapping it in SomeException --- servant-client/src/Servant/Common/Req.hs | 6 +++--- servant-client/test/Servant/ClientSpec.hs | 5 ----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/servant-client/src/Servant/Common/Req.hs b/servant-client/src/Servant/Common/Req.hs index ffd4569f..d6933e34 100644 --- a/servant-client/src/Servant/Common/Req.hs +++ b/servant-client/src/Servant/Common/Req.hs @@ -53,7 +53,7 @@ data ServantError , responseBody :: ByteString } | ConnectionError - { connectionError :: String + { connectionError :: SomeException } deriving (Show, Typeable) @@ -156,7 +156,7 @@ performRequest reqMethod req isWantedStatus reqHost = do Client.httpLbs request manager case eResponse of Left err -> - left $ ConnectionError (show err) + left . ConnectionError $ SomeException err Right response -> do let status = Client.responseStatus response @@ -192,4 +192,4 @@ performRequestNoBody reqMethod req wantedStatus reqHost = do catchConnectionError :: IO a -> IO (Either ServantError a) catchConnectionError action = catch (Right <$> action) $ \e -> - pure . Left . ConnectionError . show $ (e :: HttpException) + pure . Left . ConnectionError $ SomeException (e :: HttpException) diff --git a/servant-client/test/Servant/ClientSpec.hs b/servant-client/test/Servant/ClientSpec.hs index 763d1397..7685a79c 100644 --- a/servant-client/test/Servant/ClientSpec.hs +++ b/servant-client/test/Servant/ClientSpec.hs @@ -68,11 +68,6 @@ instance FromFormUrlEncoded Person where a <- lookupEither "age" xs return $ Person (T.unpack n) (read $ T.unpack a) -deriving instance Eq ServantError - -instance Eq C.HttpException where - a == b = show a == show b - alice :: Person alice = Person "Alice" 42