@@ -12,11 +12,12 @@ module Network.HTTP.Affjax
1212 , delete , delete_
1313 ) where
1414
15+ import Control.Bind ((<=<))
1516import Control.Monad.Aff (Aff (), makeAff , makeAff' , Canceler (..))
1617import Control.Monad.Eff (Eff ())
1718import Control.Monad.Eff.Exception (Error (), error )
1819import Data.Either (Either (..))
19- import Data.Foreign (Foreign (..), F ())
20+ import Data.Foreign (Foreign (..), F (), parseJSON , readString )
2021import Data.Function (Fn5 (), runFn5 , Fn4 (), runFn4 )
2122import Data.Maybe (Maybe (..), maybe )
2223import 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
141146type AjaxRequest =
142147 { method :: String
0 commit comments