module Network.Bugsnag.Settings
( BugsnagApiKey(..)
, BugsnagSettings(..)
, newBugsnagSettings
, bugsnagSettings
, bugsnagShouldNotify
) where
import Prelude
import Data.Aeson (FromJSON)
import Data.String
import Data.Text (Text)
import qualified Data.Text as T
import Network.Bugsnag.BeforeNotify
import Network.Bugsnag.CodeIndex
import Network.Bugsnag.Event
import Network.Bugsnag.Exception
import Network.Bugsnag.ReleaseStage
import Network.HTTP.Client
import Network.HTTP.Client.TLS
newtype BugsnagApiKey = BugsnagApiKey
{ BugsnagApiKey -> Text
unBugsnagApiKey :: Text
}
deriving newtype (Value -> Parser [BugsnagApiKey]
Value -> Parser BugsnagApiKey
(Value -> Parser BugsnagApiKey)
-> (Value -> Parser [BugsnagApiKey]) -> FromJSON BugsnagApiKey
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [BugsnagApiKey]
$cparseJSONList :: Value -> Parser [BugsnagApiKey]
parseJSON :: Value -> Parser BugsnagApiKey
$cparseJSON :: Value -> Parser BugsnagApiKey
FromJSON, String -> BugsnagApiKey
(String -> BugsnagApiKey) -> IsString BugsnagApiKey
forall a. (String -> a) -> IsString a
fromString :: String -> BugsnagApiKey
$cfromString :: String -> BugsnagApiKey
IsString)
instance Show BugsnagApiKey where
show :: BugsnagApiKey -> String
show = Text -> String
T.unpack (Text -> String)
-> (BugsnagApiKey -> Text) -> BugsnagApiKey -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BugsnagApiKey -> Text
unBugsnagApiKey
data BugsnagSettings = BugsnagSettings
{ BugsnagSettings -> BugsnagApiKey
bsApiKey :: BugsnagApiKey
, BugsnagSettings -> Maybe Text
bsAppVersion :: Maybe Text
, BugsnagSettings -> BugsnagReleaseStage
bsReleaseStage :: BugsnagReleaseStage
, BugsnagSettings -> [BugsnagReleaseStage]
bsNotifyReleaseStages :: [BugsnagReleaseStage]
, BugsnagSettings -> BeforeNotify
bsBeforeNotify :: BeforeNotify
, BugsnagSettings -> BugsnagException -> Bool
bsIgnoreException :: BugsnagException -> Bool
, BugsnagSettings -> Manager
bsHttpManager :: Manager
, BugsnagSettings -> Maybe CodeIndex
bsCodeIndex :: Maybe CodeIndex
}
bugsnagSettings :: BugsnagApiKey -> Manager -> BugsnagSettings
bugsnagSettings :: BugsnagApiKey -> Manager -> BugsnagSettings
bugsnagSettings BugsnagApiKey
apiKey Manager
manager = BugsnagSettings :: BugsnagApiKey
-> Maybe Text
-> BugsnagReleaseStage
-> [BugsnagReleaseStage]
-> BeforeNotify
-> (BugsnagException -> Bool)
-> Manager
-> Maybe CodeIndex
-> BugsnagSettings
BugsnagSettings
{ bsApiKey :: BugsnagApiKey
bsApiKey = BugsnagApiKey
apiKey
, bsAppVersion :: Maybe Text
bsAppVersion = Maybe Text
forall a. Maybe a
Nothing
, bsReleaseStage :: BugsnagReleaseStage
bsReleaseStage = BugsnagReleaseStage
ProductionReleaseStage
, bsNotifyReleaseStages :: [BugsnagReleaseStage]
bsNotifyReleaseStages = [BugsnagReleaseStage
ProductionReleaseStage]
, bsBeforeNotify :: BeforeNotify
bsBeforeNotify = BeforeNotify
forall a. a -> a
id
, bsIgnoreException :: BugsnagException -> Bool
bsIgnoreException = Bool -> BugsnagException -> Bool
forall a b. a -> b -> a
const Bool
False
, bsHttpManager :: Manager
bsHttpManager = Manager
manager
, bsCodeIndex :: Maybe CodeIndex
bsCodeIndex = Maybe CodeIndex
forall a. Maybe a
Nothing
}
bugsnagShouldNotify :: BugsnagSettings -> BugsnagEvent -> Bool
bugsnagShouldNotify :: BugsnagSettings -> BugsnagEvent -> Bool
bugsnagShouldNotify BugsnagSettings
settings BugsnagEvent
event
| BugsnagSettings -> BugsnagReleaseStage
bsReleaseStage BugsnagSettings
settings BugsnagReleaseStage -> [BugsnagReleaseStage] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` BugsnagSettings -> [BugsnagReleaseStage]
bsNotifyReleaseStages BugsnagSettings
settings = Bool
False
| BugsnagSettings -> BugsnagException -> Bool
bsIgnoreException BugsnagSettings
settings (BugsnagException -> Bool) -> BugsnagException -> Bool
forall a b. (a -> b) -> a -> b
$ BugsnagEvent -> BugsnagException
beException BugsnagEvent
event = Bool
False
| Bool
otherwise = Bool
True
newBugsnagSettings :: BugsnagApiKey -> IO BugsnagSettings
newBugsnagSettings :: BugsnagApiKey -> IO BugsnagSettings
newBugsnagSettings BugsnagApiKey
apiKey = BugsnagApiKey -> Manager -> BugsnagSettings
bugsnagSettings BugsnagApiKey
apiKey (Manager -> BugsnagSettings) -> IO Manager -> IO BugsnagSettings
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO Manager
getGlobalManager