refactor(health): simplfy code following HealthR handler

This commit is contained in:
Steffen Jost 2024-02-06 10:48:54 +00:00
parent 42f1a802b5
commit 4a843fe30e

View File

@ -68,28 +68,25 @@ matchesUniqueInterfaceHealth (UniqueInterfaceHealth ai as aw) (UniqueInterfaceHe
getHealthInterfaceR :: [Text] -> Handler TypedContent
getHealthInterfaceR (dropWhile (=="force") -> ris) = do -- for backwards compatibility we ignore leading "force"
getHealthInterfaceR (dropWhile (=="force") -> ris) = do -- for backwards compatibility we ignore leading "force"
let interfs = splitInterfaces $ identifyInterfaces ris
(missing, allok, res, iltable) <- runInterfaceLogTable interfs
when missing notFound -- send 404 if any requested interface was not found
let respond = sendResponseStatus (bool internalServerError500 status200 allok)
plainMsg = if allok
then "Interfaces are healthy"
else "Unhealthy interfaces: " <> Text.intercalate ", " [iface | (iface, False) <- res]
selectRep $ do
provideRep $ do
content <- siteLayoutMsg MsgMenuHealthInterface $ do
when missing notFound -- send 404 if any requested interface was not found
let ihstatus = if allok then status200
else internalServerError500
plainMsg = if allok then "Interfaces are healthy."
else "Unhealthy interfaces: " <> Text.intercalate ", " [iface | (iface, False) <- res]
sendResponseStatus ihstatus <=< selectRep $ do
provideRep . siteLayoutMsg MsgMenuHealthInterface $ do
setTitleI MsgMenuHealthInterface
[whamlet|
<div>
#{plainMsg}
<div>
^{iltable}
|]
respond content
|]
provideRep $ do
respond $ RepPlain $ toContent plainMsg
provideRep $ return $ RepPlain $ toContent plainMsg