Implement logging in terms of IOE and adapt locally; include stdout logging on adapt catches
This commit is contained in:
		
							
								
								
									
										19
									
								
								src/Core.hs
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								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 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 James Eversole
					James Eversole