I have an HTTP application server that needs to exit when handling a certain request under certain conditions (in order to be restarted by a supervisor).
Given a main like:
import Network.Wai.Handler.Warp (run)
main :: IO ()
main = do
config <- readConfig
run (portNumber config) (makeApp config)
and a handler something like:
livenessServer1 :: UTCTime -> FilePath -> Server LivenessProbeAPI1
livenessServer1 initialModificationTime monitorPath = do
mtime <- liftIO $ getModificationTime monitorPath
case mtime == initialModificationTime of
True -> return $ Liveness initialModificationTime mtime
False -> throwError $ err500 { errBody = "File modified." }
How do I cause the process to end after delivering the 500 response?
error "Oops!"
to throw an error, as by default Warp doesnt handle errors. – Trunk