    {-# LANGUAGE ExistentialQuantification #-}
    module Web.Scotty.Exceptions (
      Handler(..)
      -- * catching
      , catch
      , catchAny
      , catches
      , catchesOptionally
      -- * trying
      , try
      , tryAny
                                 ) where

    import Data.Maybe (maybeToList)

    import UnliftIO (MonadUnliftIO(..), catch, catchAny, catches, try, tryAny, Handler(..))

    -- | Handlers are tried sequentially
    catchesOptionally :: MonadUnliftIO m =>
                         m a
                      -> Maybe (Handler m a) -- ^ if present, this 'Handler' is tried first
                      -> [Handler m a] -- ^ these are tried in order
                      -> m a
    catchesOptionally :: forall (m :: * -> *) a.
    MonadUnliftIO m =>
    m a -> Maybe (Handler m a) -> [Handler m a] -> m a
    catchesOptionally m a
    io Maybe (Handler m a)
    mh [Handler m a]
    handlers = m a
    io m a -> [Handler m a] -> m a
    forall (m :: * -> *) a.
    MonadUnliftIO m =>
    m a -> [Handler m a] -> m a
    `catches` (Maybe (Handler m a) -> [Handler m a]
    forall a. Maybe a -> [a]
    maybeToList Maybe (Handler m a)
    mh [Handler m a] -> [Handler m a] -> [Handler m a]
    forall a. Semigroup a => a -> a -> a
    <> [Handler m a]
    handlers)