@@ -12,11 +12,12 @@ module Network.HTTP.Affjax
12
12
, delete , delete_
13
13
) where
14
14
15
+ import Control.Bind ((<=<))
15
16
import Control.Monad.Aff (Aff (), makeAff , makeAff' , Canceler (..))
16
17
import Control.Monad.Eff (Eff ())
17
18
import Control.Monad.Eff.Exception (Error (), error )
18
19
import Data.Either (Either (..))
19
- import Data.Foreign (Foreign (..), F ())
20
+ import Data.Foreign (Foreign (..), F (), parseJSON , readString )
20
21
import Data.Function (Fn5 (), runFn5 , Fn4 (), runFn4 )
21
22
import Data.Maybe (Maybe (..), maybe )
22
23
import Data.Nullable (Nullable (), toNullable )
@@ -134,9 +135,13 @@ affjax' req eb cb =
134
135
, password: toNullable req.password
135
136
}
136
137
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
138
139
Left err -> eb $ error (show err )
139
140
Right res' -> cb res'
141
+ fromResponse' :: ResponseContent -> F b
142
+ fromResponse' = case (responseType :: ResponseType b ) of
143
+ JSONResponse -> fromResponse <= < parseJSON <= < readString
144
+ _ -> fromResponse
140
145
141
146
type AjaxRequest =
142
147
{ method :: String
0 commit comments