packages feed

bugsnag-types-1.1.0.1: src/Data/Bugsnag/Types/Exception.hs

module Data.Bugsnag.Types.Exception
  ( Exception (..)
  , exampleException
  ) where

import Data.Bugsnag.Types.Prelude

import Data.Bugsnag.Types.Stackframe
import Data.Bugsnag.Types.ErrorType

data Exception = Exception
  { errorClass :: Text
  -- ^ The class of error which occurred. This field is used to group the
  -- errors together so should not contain any contextual information that
  -- would prevent correct grouping. This would ordinarily be the Exception
  -- name when dealing with an exception.
  , message :: Maybe Text
  -- ^ The error message associated with the error. Usually this will contain
  -- some information about this specific instance of the error and is not
  -- used to group the errors.
  , stacktrace :: [Stackframe]
  -- ^ An array of stackframe objects. Each object represents one line in the
  -- exception\'s stacktrace. This information is used to help with error
  -- grouping, as well as displaying it to the user.
  , type_ :: Maybe ErrorType
  }
  deriving stock (Eq, Show, Generic)

instance FromJSON Exception where
  parseJSON = genericParseJSON aesonOptions

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

exampleException :: Exception
exampleException = Exception
  { errorClass = "NoMethodError"
  , message = Just "Unable to connect to database"
  , stacktrace = [exampleStackframe]
  , type_ = Just exampleErrorType
  }