packages feed

bugsnag-types-1.1.0.0: src/Data/Bugsnag/Types/Payload.hs

module Data.Bugsnag.Types.Payload
  ( Payload (..)
  , examplePayload
  ) where

import Data.Bugsnag.Types.Prelude


import Data.Bugsnag.Types.Notifier
import Data.Bugsnag.Types.Event

data Payload = Payload
  { apiKey :: Maybe Text
  -- ^ The API Key associated with the project. Informs Bugsnag which project has
  -- generated this error.
  -- 
  -- This is provided for legacy notifiers. It is preferable to use the `Bugsnag-Api-Key` header instead.
  , payloadVersion :: Text
  -- ^ The version number of the payload. This is currently `5`.
  -- 
  -- The `Bugsnag-Payload-Version` header should be included as well, for compatibility reasons.
  , notifier :: Notifier
  -- ^ Describes the notifier itself. These properties are used within Bugsnag to
  -- track error rates from a notifier.
  , events :: [Event]
  -- ^ An array of error events that Bugsnag should be notified of. A notifier
  -- can choose to group notices into an array to minimize network traffic, or
  -- can notify Bugsnag each time an event occurs. Should contain at least 1 event.
  }
  deriving stock (Eq, Show, Generic)

instance FromJSON Payload where
  parseJSON = genericParseJSON aesonOptions

instance ToJSON Payload where
  toJSON = genericToJSON aesonOptions
  toEncoding = genericToEncoding aesonOptions

examplePayload :: Payload
examplePayload = Payload
  { apiKey = Just "YOUR-NOTIFIER-API-KEY"
  , payloadVersion = "5"
  , notifier = exampleNotifier
  , events = [exampleEvent]
  }