packages feed

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

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

import Data.Bugsnag.Types.Prelude

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

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, Generic, Show)

instance FromJSON Exception where
  parseJSON = genericParseJSON aesonOptions

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

defaultException :: Text -> [Stackframe] -> Exception
defaultException errorClass stacktrace =
  Exception
    { errorClass
    , stacktrace
    , message = Nothing
    , type_ = Nothing
    }

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