Skip to content

Commit

Permalink
Updates for affjax 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kritzcreek committed Aug 14, 2018
1 parent ae98176 commit 1ad6e7c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"purescript-xpath": "cryogenian/purescript-xpath#compiler/0.12",
"purescript-argonaut-core": "^4.0.0",
"purescript-argonaut-codecs": "^4.0.0",
"purescript-affjax": "^6.0.0",
"purescript-affjax": "^7.0.0",
"purescript-css": "^4.0.0",
"purescript-node-fs-aff": "^6.0.0",
"purescript-run": "cryogenian/purescript-run#compiler/0.12"
Expand Down
23 changes: 13 additions & 10 deletions src/Lunapark/Endpoint.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ module Lunapark.Endpoint where

import Prelude

import Effect.Aff (Aff)
import Affjax as N
import Affjax.RequestBody as NQ
import Affjax.ResponseFormat as NR
import Affjax.StatusCode (StatusCode(..))
import Data.Argonaut.Core (Json)
import Data.Argonaut.Decode.Combinators ((.?)) as J
import Data.Argonaut.Decode.Class (decodeJson) as J
import Data.Argonaut.Decode.Combinators ((.?)) as J
import Data.Bifunctor (lmap)
import Data.Either (Either(..))
import Data.Either (Either(..), either)
import Data.Foldable as F
import Data.List as L
import Data.Maybe (Maybe(..))
import Data.Newtype (un)
import Effect.Aff (Aff)
import Lunapark.Error as LE
import Lunapark.Types as LT
import Network.HTTP.Affjax.Response as NR
import Network.HTTP.Affjax.Request as NQ
import Network.HTTP.Affjax as N
import Network.HTTP.StatusCode (StatusCode(..))

data EndpointPart
= Session
Expand Down Expand Up @@ -168,12 +168,15 @@ printPart = case _ of
LongClick"longclick"
Flick"flick"

handleAPIError N.AffjaxResponse Json Either LE.Error Json
handleAPIError
N.Response (Either N.ResponseFormatError Json)
Either LE.Error Json
handleAPIError r = case r.status of
StatusCode 200 → lmap LE.unknownError do
obj ← J.decodeJson r.response
obj ← J.decodeJson =<< lmap N.printResponseFormatError r.body
obj J..? "value"
code → Left $ LE.fromJson r.response
code →
Left $ either (LE.unknownError <<< N.printResponseFormatError) LE.fromJson r.body

get String Endpoint Aff (Either LE.Error Json)
get uri ep = map handleAPIError $ N.get NR.json (uri <> print ep)
Expand Down

0 comments on commit 1ad6e7c

Please sign in to comment.