这个错误意味着什么 - Uncaught TypeError:已经读过了吗?

时间:2016-01-14 09:51:57

标签: javascript promise uncaught-typeerror

在Javascript中,何时抛出此错误?

enter image description here

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
}

这是原生承诺错误吗?这意味着什么?谷歌没有找到任何结果。

2 个答案:

答案 0 :(得分:57)

我认为这意味着已经通过使用.json()。text()等来读取正文...当你运行x.json()时,它会获取响应的主体并将其读入JSON。如果您尝试再次运行x.json(),它将为您提供该错误。因此,您只能使用一次these方法。所以我假设你的代码中某处使用Body方法之一再次读取相同响应的主体。

我认为这就是他们提供Body.bodyUsed方法的原因。所以你可以看看它是否已被阅读。

答案 1 :(得分:6)

此错误表示您已经多次解决了承诺(在这种情况下,您使用Body.json())。

您可以从下面的参考ID中检查响应体方法,并且您需要一个标记来检查承诺是否已经解决:在这种情况下,您可以使用Body.bodyUsed

参考:https://developer.mozilla.org/en-US/docs/Web/API/Response

HTH

相关问题