/f.hs Secret
Last active
December 10, 2021 10:57
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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