Skip to content

Commit c6298a6

Browse files
committed
Add rollbar-yesod
1 parent 3658970 commit c6298a6

File tree

13 files changed

+151
-5
lines changed

13 files changed

+151
-5
lines changed

cabal.project

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ packages:
22
rollbar-cli/
33
rollbar-client/
44
rollbar-wai/
5+
rollbar-yesod/

rollbar-wai/src/Rollbar/Wai.hs

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ import Data.Aeson
1919
import Network.HTTP.Types (renderQuery)
2020
import Rollbar.Client
2121

22-
rollbarOnException :: Settings -> Maybe W.Request -> SomeException -> IO ()
23-
rollbarOnException settings mreq ex = void $ forkIO $
22+
rollbarOnException
23+
:: MonadIO m
24+
=> Settings
25+
-> Maybe W.Request
26+
-> SomeException
27+
-> m ()
28+
rollbarOnException settings mreq ex = void $ liftIO $ forkIO $
2429
runRollbar settings $ do
25-
itemData <- mkData $ PayloadTrace $ Trace [] $ mkException ex
30+
idata <- mkData $ PayloadTrace $ Trace [] $ mkException ex
2631
mdreq <- mapM mkRequest mreq
27-
void $ createItem $ Item itemData { dataRequest = mdreq }
32+
void $ createItem $ Item idata { dataRequest = mdreq }
2833

2934
mkRequest :: MonadIO m => W.Request -> m Request
3035
mkRequest req = liftIO $ do
@@ -38,7 +43,7 @@ mkRequest req = liftIO $ do
3843
, requestGet = HM.fromList $ fmap toQuery $ W.queryString req
3944
, requestQueryStrings = T.decodeUtf8 $ renderQuery False $ W.queryString req
4045
, requestPost = HM.fromList $ fmap toParam params
41-
, requestBody = mempty
46+
, requestBody = ""
4247
, requestUserIp = ""
4348
}
4449
where

rollbar-yesod/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.stack-work/
2+
*~

rollbar-yesod/ChangeLog.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog for rollbar-yesod
2+
3+
## Unreleased changes

rollbar-yesod/LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE

rollbar-yesod/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# rollbar-yesod

rollbar-yesod/Setup.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

rollbar-yesod/package.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: rollbar-yesod
2+
version: 0.1.0
3+
github: "stackbuilders/rollbar-haskell"
4+
license: MIT
5+
author: "Stack Builders Inc."
6+
maintainer: "Sebastián Estrella <[email protected]>"
7+
copyright: "2020 Stack Builders Inc."
8+
tested-with: GHC ==8.6.5, GHC ==8.8.4, GHC ==8.10.2
9+
10+
extra-source-files:
11+
- README.md
12+
- ChangeLog.md
13+
14+
# Metadata used when publishing your package
15+
# synopsis: Short description of your package
16+
# category: Web
17+
18+
description:
19+
Please see the README on GitHub at
20+
<https://github.com/stackbuilders/rollbar-haskell/tree/master/rollbar-yesod>
21+
22+
dependencies:
23+
- base >= 4.12 && < 5
24+
25+
library:
26+
source-dirs: src
27+
dependencies:
28+
- exceptions
29+
- rollbar-client
30+
- rollbar-wai
31+
- yesod-core
32+
33+
tests:
34+
rollbar-yesod-test:
35+
main: Spec.hs
36+
source-dirs: test
37+
ghc-options:
38+
- -threaded
39+
- -rtsopts
40+
- -with-rtsopts=-N
41+
dependencies:
42+
- rollbar-yesod

rollbar-yesod/rollbar-yesod.cabal

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
cabal-version: 1.12
2+
3+
-- This file has been generated from package.yaml by hpack version 0.33.0.
4+
--
5+
-- see: https://github.com/sol/hpack
6+
--
7+
-- hash: 70eae7a982eea17f10d248ef08146e18198494e0bbd1de8bdc6040d9ed7396fd
8+
9+
name: rollbar-yesod
10+
version: 0.1.0
11+
description: Please see the README on GitHub at <https://github.com/stackbuilders/rollbar-haskell/tree/master/rollbar-yesod>
12+
homepage: https://github.com/stackbuilders/rollbar-haskell#readme
13+
bug-reports: https://github.com/stackbuilders/rollbar-haskell/issues
14+
author: Stack Builders Inc.
15+
maintainer: Sebastián Estrella <[email protected]>
16+
copyright: 2020 Stack Builders Inc.
17+
license: MIT
18+
license-file: LICENSE
19+
tested-with: GHC ==8.6.5, GHC ==8.8.4, GHC ==8.10.2
20+
build-type: Simple
21+
extra-source-files:
22+
README.md
23+
ChangeLog.md
24+
25+
source-repository head
26+
type: git
27+
location: https://github.com/stackbuilders/rollbar-haskell
28+
29+
library
30+
exposed-modules:
31+
Rollbar.Yesod
32+
other-modules:
33+
Paths_rollbar_yesod
34+
hs-source-dirs:
35+
src
36+
build-depends:
37+
base >=4.12 && <5
38+
, exceptions
39+
, rollbar-client
40+
, rollbar-wai
41+
, yesod-core
42+
default-language: Haskell2010
43+
44+
test-suite rollbar-yesod-test
45+
type: exitcode-stdio-1.0
46+
main-is: Spec.hs
47+
other-modules:
48+
Paths_rollbar_yesod
49+
hs-source-dirs:
50+
test
51+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
52+
build-depends:
53+
base >=4.12 && <5
54+
, rollbar-yesod
55+
default-language: Haskell2010

rollbar-yesod/src/Rollbar/Yesod.hs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{-# LANGUAGE FlexibleContexts #-}
2+
3+
module Rollbar.Yesod
4+
( rollbarYesodMiddleware
5+
) where
6+
7+
import Control.Monad
8+
import Control.Monad.Catch
9+
import Rollbar.Client
10+
import Rollbar.Wai (rollbarOnException)
11+
import Yesod.Core
12+
import Yesod.Core.Types (HandlerContents)
13+
14+
rollbarYesodMiddleware
15+
:: MonadCatch (HandlerFor site)
16+
=> Settings
17+
-> HandlerFor site res
18+
-> HandlerFor site res
19+
rollbarYesodMiddleware settings handler = handler `catch` \ex -> do
20+
unless (isHandlerContents ex) $ do
21+
req <- waiRequest
22+
rollbarOnException settings (Just req) ex
23+
24+
throwM ex
25+
26+
isHandlerContents :: SomeException -> Bool
27+
isHandlerContents = maybe False bar . fromException
28+
where
29+
bar :: HandlerContents -> Bool
30+
bar = const True

rollbar-yesod/test/Spec.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main :: IO ()
2+
main = putStrLn "Test suite not yet implemented"

stack-14.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ packages:
44
- ./rollbar-cli
55
- ./rollbar-client
66
- ./rollbar-wai
7+
- ./rollbar-yesod

stack.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ packages:
44
- ./rollbar-cli
55
- ./rollbar-client
66
- ./rollbar-wai
7+
- ./rollbar-yesod

0 commit comments

Comments
 (0)