Skip to content

Commit

Permalink
rollbar-wai - Adding missing documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Oct 21, 2020
1 parent 578662a commit 4b4f905
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 3 additions & 2 deletions rollbar-wai/example/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import Rollbar.Wai
main :: IO ()
main = do
settings <- readSettings "rollbar.yaml"
let warpSettings = setOnException (rollbarOnException settings) defaultSettings
runSettings warpSettings app
runSettings
(setOnException (rollbarOnException settings) defaultSettings)
app

app :: Application
app _ _ = error "Boom"
23 changes: 23 additions & 0 deletions rollbar-wai/src/Rollbar/Wai.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
-- Copyright: (c) 2020 Stack Builders Inc.
-- License: MIT
-- Maintainer: Sebastián Estrella <[email protected]>
--
-- For a fully working example check the following link:
--
-- <https://github.com/stackbuilders/rollbar-haskell/blob/master/rollbar-wai/example/Main.hs>
module Rollbar.Wai
( rollbarOnException
, rollbarOnExceptionWith
Expand All @@ -26,13 +30,29 @@ import Data.Aeson
import Network.HTTP.Types (renderQuery)
import Rollbar.Client

-- | Sends the captured 'SomeException' to Rollbar API using the given
-- 'Settings'. Under the hood, this function uses 'createItem' function from
-- rollbar-client.
--
-- __Example__
--
-- > settings <- readSettings "rollbar.yaml"
-- > runSettings
-- > (setOnException (rollbarOnException settings) defaultSettings)
-- > app
--
-- @since 0.1.0
rollbarOnException
:: Settings
-> Maybe W.Request
-> SomeException
-> IO ()
rollbarOnException = rollbarOnExceptionWith (void . createItem)

-- | Similar to 'rollbarOnExceptionWith', but it allows customize the function
-- used to send the 'Item' to Rollbar.
--
-- @since 0.1.0
rollbarOnExceptionWith
:: (Item -> Rollbar ())
-> Settings
Expand All @@ -45,6 +65,9 @@ rollbarOnExceptionWith f settings waiRequest ex =
request <- mapM mkRequest waiRequest
f item { itemRequest = request }

-- | Transforms a Wai 'W.Request' into a Rollbar 'Request'.
--
-- @since 0.1.0
mkRequest :: MonadIO m => W.Request -> m Request
mkRequest req = liftIO $ do
(params, _) <- W.parseRequestBody ignoreFiles req
Expand Down
2 changes: 1 addition & 1 deletion rollbar-yesod/src/Rollbar/Yesod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ rollbarYesodMiddleware = rollbarYesodMiddlewareWith $ \settings request ex ->
liftIO $ rollbarOnException settings (Just request) ex

-- | Similar to 'rollbarYesodMiddleware', but it allows customize the function
-- used to send the 'SomeException' capture from a handler to Rollbar.
-- used to send the 'SomeException' captured from a handler to Rollbar.
rollbarYesodMiddlewareWith
:: (HasSettings m, MonadHandler m, MonadUnliftIO m)
=> (Settings -> W.Request -> SomeException -> m ())
Expand Down

0 comments on commit 4b4f905

Please sign in to comment.