update docs, better names

rename catchBehvaior -> catchHandlerExceptions
rename shouldCatch -> catchHanlderExceptions
This commit is contained in:
Jappie Klooster 2022-07-20 12:40:00 +02:00
parent 5ac65db1bf
commit 01ccea46cc
4 changed files with 17 additions and 16 deletions

View File

@ -75,14 +75,14 @@ class RenderRoute site => Yesod site where
approot = guessApproot approot = guessApproot
-- | @since 1.6.24.0 -- | @since 1.6.24.0
-- Should we catch an exception, or rethrow it. -- allows the user to specify how exceptions are cought.
-- Rethrowing an exception lets the webserver deal with it -- by default all async exceptions are thrown and synchronous
-- (usually warp). -- exceptions render a 500 page.
-- catching allows yesod to render the error page. -- One could override this for example to catch all exceptions
-- the default 'rethrowAsync' is to rethrow async -- aside connection closed by peer to let yesod do more 500 page
-- exceptions. -- rendering (instead of warp).
catchBehavior :: site -> IO a -> (SomeException -> IO a) -> IO a catchHandlerExceptions :: site -> IO a -> (SomeException -> IO a) -> IO a
catchBehavior _ = catch catchHandlerExceptions _ = catch
-- | Output error response pages. -- | Output error response pages.
-- --

View File

@ -99,7 +99,7 @@ basicRunHandler rhe handler yreq resState = do
-- Run the handler itself, capturing any runtime exceptions and -- Run the handler itself, capturing any runtime exceptions and
-- converting them into a @HandlerContents@ -- converting them into a @HandlerContents@
contents' <- unsafeAsyncCatch (rheShouldCatch rhe) contents' <- unsafeAsyncCatch (rheCatchHandlerExceptions rhe)
(do (do
res <- unHandlerFor handler (hd istate) res <- unHandlerFor handler (hd istate)
tc <- evaluate (toTypedContent res) tc <- evaluate (toTypedContent res)
@ -223,8 +223,8 @@ runHandler rhe@RunHandlerEnv {..} handler yreq = withInternalState $ \resState -
-- Evaluate the unfortunately-lazy session and headers, -- Evaluate the unfortunately-lazy session and headers,
-- propagating exceptions into the contents -- propagating exceptions into the contents
(finalSession, contents1) <- evalFallback rheShouldCatch contents0 (ghsSession state) (finalSession, contents1) <- evalFallback rheCatchHandlerExceptions contents0 (ghsSession state)
(headers, contents2) <- evalFallback rheShouldCatch contents1 (appEndo (ghsHeaders state) []) (headers, contents2) <- evalFallback rheCatchHandlerExceptions contents1 (appEndo (ghsHeaders state) [])
contents3 <- (evaluate contents2) `catchAny` (fmap HCError . toErrorHandler) contents3 <- (evaluate contents2) `catchAny` (fmap HCError . toErrorHandler)
-- Convert the HandlerContents into the final YesodResponse -- Convert the HandlerContents into the final YesodResponse
@ -288,7 +288,7 @@ runFakeHandler fakeSessionMap logger site handler = liftIO $ do
, rheLog = messageLoggerSource site $ logger site , rheLog = messageLoggerSource site $ logger site
, rheOnError = errHandler , rheOnError = errHandler
, rheMaxExpires = maxExpires , rheMaxExpires = maxExpires
, rheShouldCatch = catchBehavior site , rheCatchHandlerExceptions = catchHandlerExceptions site
} }
handler' handler'
errHandler err req = do errHandler err req = do
@ -365,7 +365,7 @@ yesodRunner handler' YesodRunnerEnv {..} route req sendResponse = do
, rheLog = log' , rheLog = log'
, rheOnError = safeEh log' , rheOnError = safeEh log'
, rheMaxExpires = maxExpires , rheMaxExpires = maxExpires
, rheShouldCatch = catchBehavior yreSite , rheCatchHandlerExceptions = catchHandlerExceptions yreSite
} }
rhe = rheSafe rhe = rheSafe
{ rheOnError = runHandler rheSafe . errorHandler { rheOnError = runHandler rheSafe . errorHandler

View File

@ -185,8 +185,9 @@ data RunHandlerEnv child site = RunHandlerEnv
, rheMaxExpires :: !Text , rheMaxExpires :: !Text
-- | @since 1.6.24.0 -- | @since 1.6.24.0
-- should we catch an exception, or rethrow it. -- catch function for rendering 500 pages on exceptions.
, rheShouldCatch :: !(forall a. IO a -> (SomeException -> IO a) -> IO a) -- by default this is catch from unliftio (rethrows all async exceptions).
, rheCatchHandlerExceptions :: !(forall a. IO a -> (SomeException -> IO a) -> IO a)
} }
data HandlerData child site = HandlerData data HandlerData child site = HandlerData

View File

@ -34,7 +34,7 @@ data MyException = MkMyException
instance Yesod CustomApp where instance Yesod CustomApp where
-- something we couldn't do before, rethrow custom exceptions -- something we couldn't do before, rethrow custom exceptions
catchBehavior _ action handler = catchHandlerExceptions _ action handler =
action `E.catch` \exception -> do action `E.catch` \exception -> do
case E.fromException exception of case E.fromException exception of
Just MkMyException -> E.throwIO MkMyException Just MkMyException -> E.throwIO MkMyException