packages feed

wai-problem-details-0.1.0.0: src/Network/Wai/Middleware/ProblemDetails/Internal/Exception.hs

module Network.Wai.Middleware.ProblemDetails.Internal.Exception
(
    ProblemDetailsException (..)
  , throwProblemDetails
  , throwProblemDetailsIO
)
where

import           Control.Exception                                    (Exception,
                                                                       throw,
                                                                       throwIO)

import           Network.Wai.Middleware.ProblemDetails.Internal.Types (ProblemDetails)

-- | The exception that can be thrown from WAI applications when using the problem details
-- middleware to send a problem details response.
newtype ProblemDetailsException = ProblemDetailsException ProblemDetails
  deriving stock Show
  deriving anyclass Exception

-- | Throw a 'ProblemDetailsException' from a pure context.
throwProblemDetails :: ProblemDetails -> a
throwProblemDetails = throw . ProblemDetailsException

-- | Throw a 'ProblemDetailsException' from an 'IO' context.
throwProblemDetailsIO :: ProblemDetails -> IO a
throwProblemDetailsIO = throwIO . ProblemDetailsException