Implement logging in terms of IOE and adapt locally; include stdout logging on adapt catches

This commit is contained in:
James Eversole 2024-10-12 17:52:12 -05:00
parent 9a8bd089e5
commit 960bb0c1a8

View File

@ -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