File: Exceptions.hs

package info (click to toggle)
haskell-scotty 0.20.1%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 256 kB
  • sloc: haskell: 1,786; makefile: 6
file content (25 lines) | stat: -rw-r--r-- 712 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{-# 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 io mh handlers = io `catches` (maybeToList mh <> handlers)