git.iko.soy/typeable/servant
on master help sign in
Merge pull request #94 from haskell-servant/tvh/simpler-error

Don't export HttpException

commitfa6cfbb539d7858bd328dce1c12c26a1ff44a399 authorAlp Mestanogullari <alpmestan@gmail.com> dateThu 2 Jul 2015, 00:59 (11 years ago) parentd27c7c0472249e
2 files changed+11−15
servant-client/src/Servant/Common/Req.hs+10−9 servant-client/test/Servant/ClientSpec.hs+1−6
servant-client/src/Servant/Common/Req.hs+10−9
@@ -48,13 +48,13 @@ data ServantError
4848 { responseContentType :: MediaType
4949 , responseBody :: ByteString
5050 }
51− | ConnectionError
52− { connectionError :: HttpException
53− }
5451 | InvalidContentTypeHeader
5552 { responseContentTypeHeader :: ByteString
5653 , responseBody :: ByteString
5754 }
55+ | ConnectionError
56+ { connectionError :: SomeException
57+ }
5858 deriving (Show, Typeable)
5959
6060instance Exception ServantError
@@ -152,11 +152,11 @@ performRequest reqMethod req isWantedStatus reqHost = do
152152 }
153153
154154 eResponse <- liftIO $ __withGlobalManager $ \ manager ->
155− catchHttpException $
156− Client.httpLbs request manager
155+ catchConnectionError $
156+ Client.httpLbs request manager
157157 case eResponse of
158158 Left err ->
159− left $ ConnectionError err
159+ left . ConnectionError $ SomeException err
160160
161161 Right response -> do
162162 let status = Client.responseStatus response
@@ -189,6 +189,7 @@ performRequestNoBody reqMethod req wantedStatus reqHost = do
189189 _ <- performRequest reqMethod req (`elem` wantedStatus) reqHost
190190 return ()
191191
192−catchHttpException :: IO a -> IO (Either HttpException a)
193−catchHttpException action =
194− catch (Right <$> action) (pure . Left)
192+catchConnectionError :: IO a -> IO (Either ServantError a)
193+catchConnectionError action =
194+ catch (Right <$> action) $ \e ->
195+ pure . Left . ConnectionError $ SomeException (e :: HttpException)
servant-client/test/Servant/ClientSpec.hs+1−6
@@ -68,11 +68,6 @@ instance FromFormUrlEncoded Person where
6868 a <- lookupEither "age" xs
6969 return $ Person (T.unpack n) (read $ T.unpack a)
7070
71−deriving instance Eq ServantError
72−
73−instance Eq C.HttpException where
74− a == b = show a == show b
75−
7671alice :: Person
7772alice = Person "Alice" 42
7873
@@ -311,7 +306,7 @@ failSpec = withFailServer $ \ baseUrl -> do
311306 it "reports ConnectionError" $ do
312307 Left res <- runEitherT getGetWrongHost
313308 case res of
314− ConnectionError (C.FailedConnectionException2 "127.0.0.1" 19872 False _) -> return ()
309+ ConnectionError _ -> return ()
315310 _ -> fail $ "expected ConnectionError, but got " <> show res
316311
317312 it "reports UnsupportedContentType" $ do