From 960bb0c1a8f86bf18de9764e5655f6a46f55fb6d Mon Sep 17 00:00:00 2001 From: James Eversole Date: Sat, 12 Oct 2024 17:52:12 -0500 Subject: [PATCH] Implement logging in terms of IOE and adapt locally; include stdout logging on adapt catches --- src/Core.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Core.hs b/src/Core.hs index c431b92..b9ce564 100644 --- a/src/Core.hs +++ b/src/Core.hs @@ -62,20 +62,21 @@ writeLog = send . WriteLog runLoggerIO :: (IOE :> es, Error ServerError :> es) => Eff (Logger : es) a -> Eff es a runLoggerIO = interpret $ \_ -> \case - WriteLog msg -> adapt $ log msg + WriteLog msg -> log msg where - log :: String -> IO () - log msg = putStrLn msg + log :: (IOE :> es, Error ServerError :> es) => String -> Eff es () + log msg = adapt $ putStrLn msg -- Utility adapt :: (IOE :> es, Error ServerError :> es) => IO a -> Eff es a -adapt m = liftIO m `catch` \(e::IOException) -> +adapt m = liftIO m `catch` \(e::IOException) -> do + liftIO $ putStrLn $ "ERROR Exception: " ++ show e throwError $ ServerError - { errHTTPCode = 500 - , errReasonPhrase = "Internal Database Error" - , errBody = fromString $ show e - , errHeaders = [] - } + { errHTTPCode = 500 + , errReasonPhrase = "Internal Server Error" + , errBody = "This incident will be investigated." + , errHeaders = [] + } -- -- Routes