Skip to content

Commit 4df71dc

Browse files
committed
servant-client-ghcjs: Throw exception on streamingRequest
Documented this behaviour in haddocks of client and ClientM
1 parent 108df08 commit 4df71dc

File tree

1 file changed

+28
-0
lines changed
  • servant-client-ghcjs/src/Servant/Client/Internal

1 file changed

+28
-0
lines changed

servant-client-ghcjs/src/Servant/Client/Internal/XhrClient.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Data.IORef (modifyIORef, newIORef, readIORef)
3535
import Data.Proxy (Proxy (..))
3636
import qualified Data.Sequence as Seq
3737
import Data.String.Conversions
38+
import Data.Typeable (Typeable)
3839
import Foreign.StablePtr
3940
import GHC.Generics
4041
import qualified GHCJS.Buffer as Buffer
@@ -51,14 +52,34 @@ newtype JSXMLHttpRequest = JSXMLHttpRequest JSVal
5152

5253
newtype JSXMLHttpRequestClass = JSXMLHttpRequestClass JSVal
5354

55+
-- | The environment in which a request is run.
5456
newtype 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!
5976
client :: HasClient ClientM api => Proxy api -> Client ClientM api
6077
client 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!
6283
newtype 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
79100
instance 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+
82109
instance RunClient ClientM where
83110
runRequest = performRequest
111+
streamingRequest _ = liftIO $ throwIO StreamingNotSupportedException
84112
throwServantError = throwError
85113

86114
instance ClientLike (ClientM a) (ClientM a) where

0 commit comments

Comments
 (0)