Skip to content

Commit aab73b7

Browse files
committed
Merge pull request #56 from garyb/restore-json-parse
Restore parse fix for JSON responses
2 parents 8316675 + e8497d8 commit aab73b7

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/Network/HTTP/Affjax.purs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Network.HTTP.Affjax
1818

1919
import Prelude
2020

21+
import Control.Bind ((<=<))
2122
import Control.Monad.Aff (Aff(), makeAff, makeAff', Canceler(..), attempt, later', forkAff, cancel)
2223
import Control.Monad.Aff.AVar (AVAR(), makeVar, takeVar, putVar)
2324
import Control.Monad.Eff (Eff())
@@ -28,7 +29,7 @@ import Control.Monad.Error.Class (throwError)
2829

2930
import Data.Array as Arr
3031
import Data.Either (Either(..), either)
31-
import Data.Foreign (Foreign())
32+
import Data.Foreign (Foreign(), F(), parseJSON, readString)
3233
import Data.Foldable (any)
3334
import Data.Function (Fn5(), runFn5, Fn4(), runFn4, on)
3435
import Data.Int (toNumber, round)
@@ -239,10 +240,15 @@ affjax' req eb cb =
239240
_ -> hs
240241

241242
cb' :: AffjaxResponse ResponseContent -> Eff (ajax :: AJAX | e) Unit
242-
cb' res = case res { response = _ } <$> fromResponse res.response of
243+
cb' res = case res { response = _ } <$> fromResponse' res.response of
243244
Left err -> eb $ error (show err)
244245
Right res' -> cb res'
245246

247+
fromResponse' :: ResponseContent -> F b
248+
fromResponse' = case snd responseSettings of
249+
JSONResponse -> fromResponse <=< parseJSON <=< readString
250+
_ -> fromResponse
251+
246252
type AjaxRequest =
247253
{ method :: String
248254
, url :: URL

src/Network/HTTP/Affjax/Response.purs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import qualified Data.ArrayBuffer.Types as A
1717

1818
import DOM.File.Types (Blob())
1919
import DOM.Node.Types (Document())
20-
import DOM.XHR.Types (FormData())
2120

2221
import Unsafe.Coerce (unsafeCoerce)
2322

@@ -76,7 +75,7 @@ instance responsableDocument :: Respondable Document where
7675

7776
instance responsableForeign :: Respondable Foreign where
7877
responseType = Tuple Nothing JSONResponse
79-
fromResponse = parseJSON <=< readString
78+
fromResponse = Right <<< unsafeCoerce
8079

8180
instance responsableString :: Respondable String where
8281
responseType = Tuple Nothing StringResponse

src/Network/HTTP/StatusCode.purs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module Network.HTTP.StatusCode where
22

33
import Prelude
44

5-
import Data.Int
6-
75
newtype StatusCode = StatusCode Int
86

97
instance eqStatusCode :: Eq StatusCode where

0 commit comments

Comments
 (0)