Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save knaman2609/ce571b102381f6bbc5f7d2131f27734a to your computer and use it in GitHub Desktop.
Save knaman2609/ce571b102381f6bbc5f7d2131f27734a to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment