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 Int -> ProblemDetailsException -> ShowS
[ProblemDetailsException] -> ShowS
ProblemDetailsException -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProblemDetailsException] -> ShowS
$cshowList :: [ProblemDetailsException] -> ShowS
show :: ProblemDetailsException -> String
$cshow :: ProblemDetailsException -> String
showsPrec :: Int -> ProblemDetailsException -> ShowS
$cshowsPrec :: Int -> ProblemDetailsException -> ShowS
Show
  deriving anyclass Show ProblemDetailsException
Typeable ProblemDetailsException
SomeException -> Maybe ProblemDetailsException
ProblemDetailsException -> String
ProblemDetailsException -> SomeException
forall e.
Typeable e
-> Show e
-> (e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> Exception e
displayException :: ProblemDetailsException -> String
$cdisplayException :: ProblemDetailsException -> String
fromException :: SomeException -> Maybe ProblemDetailsException
$cfromException :: SomeException -> Maybe ProblemDetailsException
toException :: ProblemDetailsException -> SomeException
$ctoException :: ProblemDetailsException -> SomeException
Exception

-- | Throw a 'ProblemDetailsException' from a pure context.
throwProblemDetails :: ProblemDetails -> a
throwProblemDetails :: forall a. ProblemDetails -> a
throwProblemDetails = forall a e. Exception e => e -> a
throw forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProblemDetails -> ProblemDetailsException
ProblemDetailsException

-- | Throw a 'ProblemDetailsException' from an 'IO' context.
throwProblemDetailsIO :: ProblemDetails -> IO a
throwProblemDetailsIO :: forall a. ProblemDetails -> IO a
throwProblemDetailsIO = forall e a. Exception e => e -> IO a
throwIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProblemDetails -> ProblemDetailsException
ProblemDetailsException