Some useful functions if you want to wrap the ServerPartT
monad transformer around the ErrorT
monad transformer. e.g.,
. This allows you to use ServerPartT
(ErrorT
e m) athrowError
and catchError
inside your monad.
- spUnwrapErrorT :: Monad m => (e -> ServerPartT m a) -> Request -> UnWebT (ErrorT e m) a -> UnWebT m a
- simpleErrorHandler :: Monad m => String -> ServerPartT m Response
- errorHandlerSP :: (Monad m, Error e) => (Request -> e -> WebT m a) -> ServerPartT (ErrorT e m) a -> ServerPartT m a
Documentation
spUnwrapErrorT :: Monad m => (e -> ServerPartT m a) -> Request -> UnWebT (ErrorT e m) a -> UnWebT m aSource
Flatten
into a ServerPartT
(ErrorT
e m) a
so that it can be use with ServerPartT
m
asimpleHTTP
. Used with
mapServerPartT'
, e.g.,
simpleHTTP conf $ mapServerPartT' (spUnWrapErrorT simpleErrorHandler) $ myPart `catchError` errorPart
Note that in this example, simpleErrorHandler
will only be run if errorPart
throws an error. You can replace simpleErrorHandler
with your own custom error handler.
see also: simpleErrorHandler
simpleErrorHandler :: Monad m => String -> ServerPartT m ResponseSource
A simple error handler which can be used with spUnwrapErrorT
.
It returns the error message as a plain text message to the browser. More sophisticated behaviour can be achieved by calling your own custom error handler instead.
see also: spUnwrapErrorT
errorHandlerSP :: (Monad m, Error e) => (Request -> e -> WebT m a) -> ServerPartT (ErrorT e m) a -> ServerPartT m aSource
This ServerPart
modifier enables the use of throwError
and
catchError
inside the WebT
actions, by adding the ErrorT
monad transformer to the stack.
You can wrap the complete second argument to simpleHTTP
in this
function.
DEPRECATED: use spUnwrapErrorT
instead.