Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
113
rated 0 times [  119] [ 6]  / answers: 1 / hits: 79044  / 9 Years ago, thu, january 14, 2016, 12:00:00

In Javascript, when is this error thrown?



enter



index.js



/**
* Created by tushar.mathur on 24/12/15.
*/
'use strict'

const _ = require('lodash')
const Rx = require('rx')
const createDataStore = require('./src/createDataStore')

const fetch = x => Rx.Observable.fromPromise(window.fetch(x))
const parseJSON = x => Rx.Observable.fromPromise(x.json()) // Line: 11 (Where the exception is thrown)
var create = _.partial(createDataStore, fetch, parseJSON)
module.exports = {
create,
// Alias for legacy purposes
createDataStore: create,
createFetchStore: create
}


Is it a native promise error? What does it imply? Google shows no result found.


More From » promise

 Answers
14

I think it means that the body has already been read by using either .json() .text() etc... When you run x.json() it takes the response's body and reads it into JSON. If you try to run x.json() again it will give you that error. So you could only use one of these methods once. So I am assuming somewhere in your code it is reading the body of the same response again using one of the Body methods.



I think that is why they offer the Body.bodyUsed method. So you can see if it has been read already.


[#63739] Monday, January 11, 2016, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
geovannil

Total Points: 226
Total Questions: 99
Total Answers: 103

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
;