git.iko.soy/typeable/servant
on master help sign in
servant-client-ghcjs: Throw exception on streamingRequest

Documented this behaviour in haddocks of client and ClientM

commit4df71dce96e17ee830feba12b9dfa655904f4883 authorFalco Peijnenburg <fpeijnenburg@gmail.com> dateSat 28 Apr 2018, 14:33 (8 years ago) parent108df08
1 file changed+28
servant-client-ghcjs/src/Servant/Client/Internal/XhrClient.hs+28
servant-client-ghcjs/src/Servant/Client/Internal/XhrClient.hs+28
@@ -35,6 +35,7 @@ import Data.IORef (modifyIORef, newIORef, readIORef)
3535import Data.Proxy (Proxy (..))
3636import qualified Data.Sequence as Seq
3737import Data.String.Conversions
38+import Data.Typeable (Typeable)
3839import Foreign.StablePtr
3940import GHC.Generics
4041import qualified GHCJS.Buffer as Buffer
@@ -51,14 +52,34 @@ newtype JSXMLHttpRequest = JSXMLHttpRequest JSVal
5152
5253newtype JSXMLHttpRequestClass = JSXMLHttpRequestClass JSVal
5354
55+-- | The environment in which a request is run.
5456newtype ClientEnv
5557 = ClientEnv
5658 { baseUrl :: BaseUrl }
5759 deriving (Eq, Show)
5860
61+-- | Generates a set of client functions for an API.
62+--
63+-- Example:
64+--
65+-- > type API = Capture "no" Int :> Get '[JSON] Int
66+-- > :<|> Get '[JSON] [Bool]
67+-- >
68+-- > api :: Proxy API
69+-- > api = Proxy
70+-- >
71+-- > getInt :: Int -> ClientM Int
72+-- > getBools :: ClientM [Bool]
73+-- > getInt :<|> getBools = client api
74+--
75+-- NOTE: Does not support constant space streaming of the request body!
5976client :: HasClient ClientM api => Proxy api -> Client ClientM api
6077client api = api `clientIn` (Proxy :: Proxy ClientM)
6178
79+-- | @ClientM@ is the monad in which client functions run. Contains the
80+-- 'BaseUrl' used for requests in the reader environment.
81+--
82+-- NOTE: Does not support constant space streaming of the request body!
6283newtype ClientM a = ClientM
6384 { runClientM' :: ReaderT ClientEnv (ExceptT ServantError IO) a }
6485 deriving ( Functor, Applicative, Monad, MonadIO, Generic
@@ -79,8 +100,15 @@ instance MonadBaseControl IO ClientM where
79100instance Alt ClientM where
80101 a <!> b = a `catchError` const b
81102
103+data StreamingNotSupportedException = StreamingNotSupportedException
104+ deriving ( Typeable, Show )
105+
106+instance Exception StreamingNotSupportedException where
107+ displayException _ = "streamingRequest: streaming is not supported!"
108+
82109instance RunClient ClientM where
83110 runRequest = performRequest
111+ streamingRequest _ = liftIO $ throwIO StreamingNotSupportedException
84112 throwServantError = throwError
85113
86114instance ClientLike (ClientM a) (ClientM a) where