From 9663e948dfce5a080bd35488e5ee339958ecf0e8 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 30 Mar 2020 09:12:15 -0700 Subject: Rescue lack of poll param --- Run/Que.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'Run/Que.hs') diff --git a/Run/Que.hs b/Run/Que.hs index 40ce5b3..4855c2d 100644 --- a/Run/Que.hs +++ b/Run/Que.hs @@ -78,10 +78,10 @@ routes = do -- ensure namespace exists app . modify <| upsertNamespace ns q <- app <| que ns qp - poll <- Scotty.param "poll" :: Scotty.ActionT Text App Text + poll <- Scotty.param "poll" !: (pure . const False) case poll of - "true" -> Scotty.stream $ streamQue q - _ -> do + True -> Scotty.stream $ streamQue q + _ -> do r <- liftIO <| takeQue q Scotty.text <| fromStrict <| Encoding.decodeUtf8 r @@ -95,6 +95,13 @@ routes = do liftIO <| pushQue (BSL.toStrict qdata) q return () +-- | recover from a scotty-thrown exception. +(!:) + :: Scotty.ActionT Text App a -- ^ action that might throw + -> (Text -> Scotty.ActionT Text App a) -- ^ a function providing a default response instead + -> Scotty.ActionT Text App a +(!:) = Scotty.rescue + -- | Forever write the data from 'Que' to 'Wai.StreamingBody'. streamQue :: Que -> Wai.StreamingBody streamQue q write _ = Go.mult q >>= loop -- cgit v1.2.3