Skip to content

Commit

Permalink
Merge pull request #25 from slamdata/ie-json
Browse files Browse the repository at this point in the history
Better fix for IE JSON responseType
  • Loading branch information
jdegoes committed Jun 8, 2015
2 parents 568bc7b + e73e848 commit a21b29f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/Network/HTTP/Affjax.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ module Network.HTTP.Affjax
, delete, delete_
) where

import Control.Bind ((<=<))
import Control.Monad.Aff (Aff(), makeAff, makeAff', Canceler(..))
import Control.Monad.Eff (Eff())
import Control.Monad.Eff.Exception (Error(), error)
import Data.Either (Either(..))
import Data.Foreign (Foreign(..), F())
import Data.Foreign (Foreign(..), F(), parseJSON, readString)
import Data.Function (Fn5(), runFn5, Fn4(), runFn4)
import Data.Maybe (Maybe(..), maybe)
import Data.Nullable (Nullable(), toNullable)
Expand Down Expand Up @@ -134,9 +135,13 @@ affjax' req eb cb =
, password: toNullable req.password
}
cb' :: AffjaxResponse ResponseContent -> Eff (ajax :: AJAX | e) Unit
cb' res = case res { response = _ } <$> fromResponse res.response of
cb' res = case res { response = _ } <$> fromResponse' res.response of
Left err -> eb $ error (show err)
Right res' -> cb res'
fromResponse' :: ResponseContent -> F b
fromResponse' = case (responseType :: ResponseType b) of
JSONResponse -> fromResponse <=< parseJSON <=< readString
_ -> fromResponse

type AjaxRequest =
{ method :: String
Expand Down
5 changes: 2 additions & 3 deletions src/Network/HTTP/Affjax/Response.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ module Network.HTTP.Affjax.Response
, Respondable, responseType, fromResponse
) where

import Control.Bind ((>=>))
import Data.Either (Either(..))
import Data.Foreign (Foreign(), F(), readString, parseJSON, unsafeReadTagged)
import Data.Foreign (Foreign(), F(), readString, unsafeReadTagged)
import DOM (Document())
import DOM.File (Blob())
import DOM.XHR (FormData())
Expand Down Expand Up @@ -64,7 +63,7 @@ instance responsableDocument :: Respondable Document where

instance responsableJSON :: Respondable Foreign where
responseType = JSONResponse
fromResponse = readString >=> parseJSON
fromResponse = Right

instance responsableString :: Respondable String where
responseType = StringResponse
Expand Down

0 comments on commit a21b29f

Please sign in to comment.