Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/f.hs Secret

Last active December 10, 2021 10:57
Show Gist options
  • Save dminuoso/66872130a9312fb7106afc1662c90124 to your computer and use it in GitHub Desktop.
Save dminuoso/66872130a9312fb7106afc1662c90124 to your computer and use it in GitHub Desktop.
exceptionJust :: Exception e
=> (e -> Maybe b)
-> (b -> IO n)
-> (r -> IO n)
-> IO r
-> IO n
exceptionJust p e h a = either pure h =<< catchJust p (fmap Right a) (fmap Left <$> e)
handler :: Int -> PendingConnection -> IO ()
handler pid pending = handle uncaught $ do
exceptionFileNotExist manifestNotFound
acceptWithManifest
(decodeManifest pid)
where
acceptWithManifest manifest = handleManifest manifest =<< acceptRequest pending
manifestNotFound _ = rejectRequestWith defaultRejectRequest{ rejectCode = 404 }
uncaught _ = rejectRequestWith defaultRejectRequest{ rejectCode = 500 }
exceptionFileNotExist =
exceptionJust (\f -> if isDoesNotExistError f then Just f else Nothing)
handleManifest :: Manifest -> Connection -> IO ()
handleManifest = ....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment