module Network.Bugsnag.Notify
( notifyBugsnag
, notifyBugsnagWith
) where
import Control.Exception (SomeException)
import Control.Monad (when)
import Data.Maybe (isJust)
import Network.Bugsnag.App
import Network.Bugsnag.BeforeNotify
import Network.Bugsnag.CodeIndex
import Network.Bugsnag.Event
import Network.Bugsnag.Exception
import Network.Bugsnag.Report
import Network.Bugsnag.Reporter
import Network.Bugsnag.Settings
import Network.Bugsnag.StackFrame
notifyBugsnag :: BugsnagSettings -> SomeException -> IO ()
notifyBugsnag = notifyBugsnagWith id
notifyBugsnagWith :: BeforeNotify -> BugsnagSettings -> SomeException -> IO ()
notifyBugsnagWith f settings ex = do
let event =
f
. bsBeforeNotify settings
. modifyStackFrames (bsCodeIndex settings)
. createApp settings
. bugsnagEvent
$ bugsnagExceptionFromSomeException ex
manager = bsHttpManager settings
apiKey = bsApiKey settings
report = bugsnagReport [event]
when (bugsnagShouldNotify settings event)
$ reportError manager apiKey report
modifyStackFrames :: Maybe CodeIndex -> BeforeNotify
modifyStackFrames Nothing = setStackFramesInProject $ const True
modifyStackFrames (Just index) =
setStackFramesInProjectBy bsfCode isJust . setStackFramesCode index
createApp :: BugsnagSettings -> BeforeNotify
createApp settings event = event
{ beApp = Just $ bugsnagApp
{ baVersion = bsAppVersion settings
, baReleaseStage = Just $ bsReleaseStage settings
}
}