Skip to content

Commit

Permalink
haddocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zocca committed Oct 4, 2023
1 parent b88cdf7 commit b868589
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
7 changes: 4 additions & 3 deletions Web/Scotty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -255,23 +255,24 @@ queryParam = Trans.queryParam

-- | Look up a capture parameter. Returns 'Nothing' if the parameter is not found or cannot be parsed at the right type.
--
-- NB : Doesn't throw exceptions.
-- NB : Doesn't throw exceptions. In particular, route pattern matching will not continue, so developers
-- must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
captureParamMaybe :: (Trans.Parsable a) => Text -> ActionM (Maybe a)
captureParamMaybe = Trans.captureParamMaybe

-- | Look up a form parameter. Returns 'Nothing' if the parameter is not found or cannot be parsed at the right type.
--
-- NB : Doesn't throw exceptions.
-- NB : Doesn't throw exceptions, so developers must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
formParamMaybe :: (Trans.Parsable a) => Text -> ActionM (Maybe a)
formParamMaybe = Trans.formParamMaybe

-- | Look up a query parameter. Returns 'Nothing' if the parameter is not found or cannot be parsed at the right type.
--
-- NB : Doesn't throw exceptions.
-- NB : Doesn't throw exceptions, so developers must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
queryParamMaybe :: (Trans.Parsable a) => Text -> ActionM (Maybe a)
Expand Down
7 changes: 4 additions & 3 deletions Web/Scotty/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -315,23 +315,24 @@ queryParam = paramWith QueryParam envQueryParams status400

-- | Look up a capture parameter. Returns 'Nothing' if the parameter is not found or cannot be parsed at the right type.
--
-- NB : Doesn't throw exceptions.
-- NB : Doesn't throw exceptions. In particular, route pattern matching will not continue, so developers
-- must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
captureParamMaybe :: (Parsable a, Monad m) => T.Text -> ActionT m (Maybe a)
captureParamMaybe = paramWithMaybe envCaptureParams

-- | Look up a form parameter. Returns 'Nothing' if the parameter is not found or cannot be parsed at the right type.
--
-- NB : Doesn't throw exceptions.
-- NB : Doesn't throw exceptions, so developers must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
formParamMaybe :: (Parsable a, Monad m) => T.Text -> ActionT m (Maybe a)
formParamMaybe = paramWithMaybe envFormParams

-- | Look up a query parameter. Returns 'Nothing' if the parameter is not found or cannot be parsed at the right type.
--
-- NB : Doesn't throw exceptions.
-- NB : Doesn't throw exceptions, so developers must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
queryParamMaybe :: (Parsable a, Monad m) => T.Text -> ActionT m (Maybe a)
Expand Down
15 changes: 11 additions & 4 deletions test/Web/ScottySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,22 @@ spec = do
describe "captureParamMaybe" $ do
withApp (
do
Scotty.get "/search/:q" $ do
Scotty.get "/a/:q" $ do
mx <- captureParamMaybe "q"
case mx of
Just (_ :: Int) -> status status500
Nothing -> status status200
Scotty.get "/b/:q" $ do
mx <- captureParamMaybe "z"
case mx of
Just (_ :: TL.Text) -> status status500
Just (_ :: TL.Text) -> text "impossible" >> status status500
Nothing -> status status200
) $ do
it "responds with 200 OK if the parameter cannot be parsed at the right type, 500 otherwise" $ do
get "/a/potato" `shouldRespondWith` 200
get "/a/42" `shouldRespondWith` 500
it "responds with 200 OK if the parameter is not found" $ do
-- get "/search/42" `shouldRespondWith` 200 { matchBody = "int" }
get "/search/potato" `shouldRespondWith` 200
get "/b/potato" `shouldRespondWith` 200


describe "text" $ do
Expand Down

0 comments on commit b868589

Please sign in to comment.