{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Servant.Client.Core.ClientError (
ClientError (..),
) where
import Prelude ()
import Prelude.Compat
import Control.DeepSeq
(NFData (..))
import Control.Exception
(SomeException (..))
import Control.Monad.Catch
(Exception)
import qualified Data.ByteString as BS
import Data.Text
(Text)
import Data.Typeable
(Typeable, typeOf)
import GHC.Generics
(Generic)
import Network.HTTP.Media
(MediaType)
import Network.HTTP.Types ()
import Servant.Client.Core.BaseUrl
import Servant.Client.Core.Internal
(mediaTypeRnf)
import Servant.Client.Core.Request
import Servant.Client.Core.Response
data ClientError =
FailureResponse (RequestF () (BaseUrl, BS.ByteString)) Response
| DecodeFailure Text Response
| UnsupportedContentType MediaType Response
| Response
| ConnectionError SomeException
deriving (Int -> ClientError -> ShowS
[ClientError] -> ShowS
ClientError -> String
(Int -> ClientError -> ShowS)
-> (ClientError -> String)
-> ([ClientError] -> ShowS)
-> Show ClientError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClientError] -> ShowS
$cshowList :: [ClientError] -> ShowS
show :: ClientError -> String
$cshow :: ClientError -> String
showsPrec :: Int -> ClientError -> ShowS
$cshowsPrec :: Int -> ClientError -> ShowS
Show, (forall x. ClientError -> Rep ClientError x)
-> (forall x. Rep ClientError x -> ClientError)
-> Generic ClientError
forall x. Rep ClientError x -> ClientError
forall x. ClientError -> Rep ClientError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ClientError x -> ClientError
$cfrom :: forall x. ClientError -> Rep ClientError x
Generic, Typeable)
instance Eq ClientError where
FailureResponse req :: RequestF () (BaseUrl, ByteString)
req res :: Response
res == :: ClientError -> ClientError -> Bool
== FailureResponse req' :: RequestF () (BaseUrl, ByteString)
req' res' :: Response
res' = RequestF () (BaseUrl, ByteString)
req RequestF () (BaseUrl, ByteString)
-> RequestF () (BaseUrl, ByteString) -> Bool
forall a. Eq a => a -> a -> Bool
== RequestF () (BaseUrl, ByteString)
req' Bool -> Bool -> Bool
&& Response
res Response -> Response -> Bool
forall a. Eq a => a -> a -> Bool
== Response
res'
DecodeFailure t :: Text
t r :: Response
r == DecodeFailure t' :: Text
t' r' :: Response
r' = Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
t' Bool -> Bool -> Bool
&& Response
r Response -> Response -> Bool
forall a. Eq a => a -> a -> Bool
== Response
r'
UnsupportedContentType mt :: MediaType
mt r :: Response
r == UnsupportedContentType mt' :: MediaType
mt' r' :: Response
r' = MediaType
mt MediaType -> MediaType -> Bool
forall a. Eq a => a -> a -> Bool
== MediaType
mt' Bool -> Bool -> Bool
&& Response
r Response -> Response -> Bool
forall a. Eq a => a -> a -> Bool
== Response
r'
InvalidContentTypeHeader r :: Response
r == InvalidContentTypeHeader r' :: Response
r' = Response
r Response -> Response -> Bool
forall a. Eq a => a -> a -> Bool
== Response
r'
ConnectionError exc :: SomeException
exc == ConnectionError exc' :: SomeException
exc' = SomeException -> SomeException -> Bool
eqSomeException SomeException
exc SomeException
exc'
where
eqSomeException :: SomeException -> SomeException -> Bool
eqSomeException (SomeException a :: e
a) (SomeException b) = e -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf e
a TypeRep -> TypeRep -> Bool
forall a. Eq a => a -> a -> Bool
== e -> TypeRep
forall a. Typeable a => a -> TypeRep
typeOf e
b
FailureResponse {} == _ = Bool
False
DecodeFailure {} == _ = Bool
False
UnsupportedContentType {} == _ = Bool
False
InvalidContentTypeHeader {} == _ = Bool
False
ConnectionError {} == _ = Bool
False
instance Exception ClientError
instance NFData ClientError where
rnf :: ClientError -> ()
rnf (FailureResponse req :: RequestF () (BaseUrl, ByteString)
req res :: Response
res) = RequestF () (BaseUrl, ByteString) -> ()
forall a. NFData a => a -> ()
rnf RequestF () (BaseUrl, ByteString)
req () -> () -> ()
forall a b. a -> b -> b
`seq` Response -> ()
forall a. NFData a => a -> ()
rnf Response
res
rnf (DecodeFailure err :: Text
err res :: Response
res) = Text -> ()
forall a. NFData a => a -> ()
rnf Text
err () -> () -> ()
forall a b. a -> b -> b
`seq` Response -> ()
forall a. NFData a => a -> ()
rnf Response
res
rnf (UnsupportedContentType mt' :: MediaType
mt' res :: Response
res) = MediaType -> ()
mediaTypeRnf MediaType
mt' () -> () -> ()
forall a b. a -> b -> b
`seq` Response -> ()
forall a. NFData a => a -> ()
rnf Response
res
rnf (InvalidContentTypeHeader res :: Response
res) = Response -> ()
forall a. NFData a => a -> ()
rnf Response
res
rnf (ConnectionError err :: SomeException
err) = SomeException
err SomeException -> () -> ()
forall a b. a -> b -> b
`seq` String -> ()
forall a. NFData a => a -> ()
rnf (SomeException -> String
forall a. Show a => a -> String
show SomeException
err)