Skip to content

Commit a21b29f

Browse files
committed
Merge pull request #25 from slamdata/ie-json
Better fix for IE JSON responseType
2 parents 568bc7b + e73e848 commit a21b29f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Diff for: src/Network/HTTP/Affjax.purs

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ module Network.HTTP.Affjax
1212
, delete, delete_
1313
) where
1414

15+
import Control.Bind ((<=<))
1516
import Control.Monad.Aff (Aff(), makeAff, makeAff', Canceler(..))
1617
import Control.Monad.Eff (Eff())
1718
import Control.Monad.Eff.Exception (Error(), error)
1819
import Data.Either (Either(..))
19-
import Data.Foreign (Foreign(..), F())
20+
import Data.Foreign (Foreign(..), F(), parseJSON, readString)
2021
import Data.Function (Fn5(), runFn5, Fn4(), runFn4)
2122
import Data.Maybe (Maybe(..), maybe)
2223
import Data.Nullable (Nullable(), toNullable)
@@ -134,9 +135,13 @@ affjax' req eb cb =
134135
, password: toNullable req.password
135136
}
136137
cb' :: AffjaxResponse ResponseContent -> Eff (ajax :: AJAX | e) Unit
137-
cb' res = case res { response = _ } <$> fromResponse res.response of
138+
cb' res = case res { response = _ } <$> fromResponse' res.response of
138139
Left err -> eb $ error (show err)
139140
Right res' -> cb res'
141+
fromResponse' :: ResponseContent -> F b
142+
fromResponse' = case (responseType :: ResponseType b) of
143+
JSONResponse -> fromResponse <=< parseJSON <=< readString
144+
_ -> fromResponse
140145

141146
type AjaxRequest =
142147
{ method :: String

Diff for: src/Network/HTTP/Affjax/Response.purs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ module Network.HTTP.Affjax.Response
44
, Respondable, responseType, fromResponse
55
) where
66

7-
import Control.Bind ((>=>))
87
import Data.Either (Either(..))
9-
import Data.Foreign (Foreign(), F(), readString, parseJSON, unsafeReadTagged)
8+
import Data.Foreign (Foreign(), F(), readString, unsafeReadTagged)
109
import DOM (Document())
1110
import DOM.File (Blob())
1211
import DOM.XHR (FormData())
@@ -64,7 +63,7 @@ instance responsableDocument :: Respondable Document where
6463

6564
instance responsableJSON :: Respondable Foreign where
6665
responseType = JSONResponse
67-
fromResponse = readString >=> parseJSON
66+
fromResponse = Right
6867

6968
instance responsableString :: Respondable String where
7069
responseType = StringResponse

0 commit comments

Comments
 (0)