Forked from knaman2609/gist:ce571b102381f6bbc5f7d2131f27734a
Last active
March 10, 2017 18:02
Revisions
-
Pauan revised this gist
Mar 10, 2017 . 1 changed file with 13 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,25 +10,20 @@ import Network.HTTP.Affjax as Ajax import Data.Either (Either(..), either) api1 = do resp <- Ajax.get "/api1" pure resp.response api2 x = do let url = "/api" <> x resp <- Ajax.get url pure resp.response main = launchAff do result <- attempt do x <- api1 y <- api2 x ... case result of Right resp -> log resp Left error -> log error -
knaman2609 created this gist
Mar 8, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ module Main where import Prelude import Control.Monad.Eff (Eff) import Control.Monad.Eff.Class import Control.Monad.Aff (launchAff, Aff, makeAff, attempt) import Control.Monad.Aff.Console (CONSOLE, log) import Control.Monad.Eff.Exception (Error, try) import Network.HTTP.Affjax as Ajax import Data.Either (Either(..), either) api1 = do e <- attempt $ Ajax.get "/api1" case e of Right resp -> pure (Right resp.response) Left error -> pure (Left "Error") api2 (Right x) = do let url = "/api" <> x e <- attempt $ Ajax.get url case e of Right resp -> pure (Right resp.response) Left error -> pure (Left "Error") api2 (Left error) = pure (Left error) main = launchAff do x <- api1 y <- api2 x case y of Right resp -> log resp Left error -> log error