summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-03-30 09:12:15 -0700
committerBen Sima <ben@bsima.me>2020-03-30 09:12:15 -0700
commit9663e948dfce5a080bd35488e5ee339958ecf0e8 (patch)
treea4cd4da00081acca37101acd9cc48bbda415f792
parenta3fa7db77828374b9de2c57adad2c26a667234bf (diff)
Rescue lack of poll param
-rw-r--r--Run/Que.hs13
1 files changed, 10 insertions, 3 deletions
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