Skip to content

Commit 254b6c1

Browse files
committed
Restore parse fix for JSON responses
1 parent 8316675 commit 254b6c1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
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

0 commit comments

Comments
 (0)