Closed
Description
The Respondable
instance for Json
looks like this:
responseTypeToString :: forall a. (ResponseType a) -> String
responseTypeToString ArrayBufferResponse = "arraybuffer"
responseTypeToString BlobResponse = "blob"
responseTypeToString DocumentResponse = "document"
responseTypeToString JSONResponse = "text" -- IE doesn't support "json" responseType
responseTypeToString StringResponse = "text"
type ResponseContent = Foreign
type F = Either ForeignError
class Respondable a where
responseType :: Tuple (Maybe MimeType) (ResponseType a)
fromResponse :: ResponseContent -> F a
instance responsableJson :: Respondable Json where
responseType = Tuple (Just applicationJSON) JSONResponse
fromResponse = Right <<< unsafeCoerce
Since responseTypeToString JSONResponse
returns "text" instead of a "json", the fromResponse
function is basically just wrapping a JavaScript string instead of a JSON blob.
This causes functions from Data.Argonaut.Decode (like toObject
) to fail when they really should be succeeding.
I think the Respondable Json
instance should look something like this:
import Data.Argonaut.Parser (jsonParser)
instance responsableJson :: Respondable Json where
responseType = Tuple (Just applicationJSON) JSONResponse
fromResponse = jsonParser <=< readString
This will give you a correct blob of JSON data and things like toObject
will succeed.
Metadata
Metadata
Assignees
Labels
No labels