on master help sign in
Don't export HttpException
ed7d235Timo von Holtz
servant-client/src/Servant/Common/Req.hs+10−9
@@ -46,13 +46,13 @@ data ServantError
46 { responseContentType :: MediaType
46 { responseContentType :: MediaType
47 , responseBody :: ByteString
47 , responseBody :: ByteString
48 }
48 }
49− | ConnectionError
50− { connectionError :: HttpException
51− }
52 | InvalidContentTypeHeader
49 | InvalidContentTypeHeader
53 { responseContentTypeHeader :: ByteString
50 { responseContentTypeHeader :: ByteString
54 , responseBody :: ByteString
51 , responseBody :: ByteString
55 }
52 }
53+ | ConnectionError
54+ { connectionError :: String
55+ }
56 deriving (Show)
56 deriving (Show)
57
57
58data Req = Req
58data Req = Req
@@ -148,11 +148,11 @@ performRequest reqMethod req isWantedStatus reqHost = do
148 }
148 }
149
149
150 eResponse <- liftIO $ __withGlobalManager $ \ manager ->
150 eResponse <- liftIO $ __withGlobalManager $ \ manager ->
151− catchHttpException $
151+ catchConnectionError $
152− Client.httpLbs request manager
152+ Client.httpLbs request manager
153 case eResponse of
153 case eResponse of
154 Left err ->
154 Left err ->
155− left $ ConnectionError err
155+ left $ ConnectionError (show err)
156
156
157 Right response -> do
157 Right response -> do
158 let status = Client.responseStatus response
158 let status = Client.responseStatus response
@@ -185,6 +185,7 @@ performRequestNoBody reqMethod req wantedStatus reqHost = do
185 _ <- performRequest reqMethod req (`elem` wantedStatus) reqHost
185 _ <- performRequest reqMethod req (`elem` wantedStatus) reqHost
186 return ()
186 return ()
187
187
188−catchHttpException :: IO a -> IO (Either HttpException a)
188+catchConnectionError :: IO a -> IO (Either ServantError a)
189−catchHttpException action =
189+catchConnectionError action =
190− catch (Right <$> action) (pure . Left)
190+ catch (Right <$> action) $ \e ->
191+ pure . Left . ConnectionError . show $ (e :: HttpException)
servant-client/test/Servant/ClientSpec.hs+1−1
@@ -303,7 +303,7 @@ failSpec = withFailServer $ \ baseUrl -> do
303 it "reports ConnectionError" $ do
303 it "reports ConnectionError" $ do
304 Left res <- runEitherT getGetWrongHost
304 Left res <- runEitherT getGetWrongHost
305 case res of
305 case res of
306− ConnectionError (C.FailedConnectionException2 "127.0.0.1" 19872 False _) -> return ()
306+ ConnectionError _ -> return ()
307 _ -> fail $ "expected ConnectionError, but got " <> show res
307 _ -> fail $ "expected ConnectionError, but got " <> show res
308
308
309 it "reports UnsupportedContentType" $ do
309 it "reports UnsupportedContentType" $ do