{-# LANGUAGE UnicodeSyntax #-} -- |Aborting the computation of 'Network.HTTP.Lucu.Resource.Resource' -- in any 'Prelude.IO' monads or arrows. module Network.HTTP.Lucu.Abortion ( Abortion , mkAbortion , mkAbortion' , abort ) where import Control.Exception import Control.Monad.Trans import Data.Ascii (Ascii, CIAscii) import Data.Monoid.Unicode import Data.Text (Text) import Network.HTTP.Lucu.Abortion.Internal import Network.HTTP.Lucu.Headers import Network.HTTP.Lucu.Response import Prelude.Unicode -- |Construct an 'Abortion' with additional headers and an optional -- message text. mkAbortion ∷ StatusCode sc ⇒ sc → [(CIAscii, Ascii)] → Maybe Text → Abortion {-# INLINE mkAbortion #-} mkAbortion sc hdr msg = Abortion { aboStatus = fromStatusCode sc , aboHeaders = toHeaders hdr , aboMessage = msg } -- |Construct an 'Abortion' without any additional headers but with a -- message text. mkAbortion' ∷ StatusCode sc ⇒ sc → Text → Abortion {-# INLINE mkAbortion' #-} mkAbortion' sc msg = Abortion { aboStatus = fromStatusCode sc , aboHeaders = (∅) , aboMessage = Just msg } -- |Throw an 'Abortion' in a 'MonadIO', including the very -- 'Network.HTTP.Lucu.Resource.Resource' monad. abort ∷ MonadIO m ⇒ Abortion → m a {-# INLINE abort #-} abort = liftIO ∘ throwIO