Merge pull request #119 from haskell-servant/existential-error
servant-client: Hide HttpException by wrapping it in SomeException
This commit is contained in:
commit
472249e92c
2 changed files with 3 additions and 8 deletions
|
@ -53,7 +53,7 @@ data ServantError
|
||||||
, responseBody :: ByteString
|
, responseBody :: ByteString
|
||||||
}
|
}
|
||||||
| ConnectionError
|
| ConnectionError
|
||||||
{ connectionError :: String
|
{ connectionError :: SomeException
|
||||||
}
|
}
|
||||||
deriving (Show, Typeable)
|
deriving (Show, Typeable)
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ performRequest reqMethod req isWantedStatus reqHost = do
|
||||||
Client.httpLbs request manager
|
Client.httpLbs request manager
|
||||||
case eResponse of
|
case eResponse of
|
||||||
Left err ->
|
Left err ->
|
||||||
left $ ConnectionError (show err)
|
left . ConnectionError $ SomeException err
|
||||||
|
|
||||||
Right response -> do
|
Right response -> do
|
||||||
let status = Client.responseStatus response
|
let status = Client.responseStatus response
|
||||||
|
@ -192,4 +192,4 @@ performRequestNoBody reqMethod req wantedStatus reqHost = do
|
||||||
catchConnectionError :: IO a -> IO (Either ServantError a)
|
catchConnectionError :: IO a -> IO (Either ServantError a)
|
||||||
catchConnectionError action =
|
catchConnectionError action =
|
||||||
catch (Right <$> action) $ \e ->
|
catch (Right <$> action) $ \e ->
|
||||||
pure . Left . ConnectionError . show $ (e :: HttpException)
|
pure . Left . ConnectionError $ SomeException (e :: HttpException)
|
||||||
|
|
|
@ -68,11 +68,6 @@ instance FromFormUrlEncoded Person where
|
||||||
a <- lookupEither "age" xs
|
a <- lookupEither "age" xs
|
||||||
return $ Person (T.unpack n) (read $ T.unpack a)
|
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 = Person "Alice" 42
|
alice = Person "Alice" 42
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue