提交 a7099768 编写于 作者: D David Graham

Extract consumed function.

上级 c7a27dc1
......@@ -70,12 +70,8 @@
}
this.blob = function() {
if (this.bodyUsed) {
return new Promise.reject(new TypeError('Body already consumed'))
}
this.bodyUsed = true
return Promise.resolve(new Blob([this.body]))
var error = this.consumed()
return error ? error : Promise.resolve(new Blob([this.body]))
}
this.formData = function() {
......@@ -83,12 +79,11 @@
}
this.json = function() {
if (this.bodyUsed) {
return new Promise.reject(new TypeError('Body already consumed'))
var error = this.consumed()
if (error) {
return error
}
this.bodyUsed = true
var body = this.body
return new Promise(function(resolve, reject) {
try {
......@@ -100,12 +95,15 @@
}
this.text = function() {
var error = this.consumed()
return error ? error : Promise.resolve(this.body)
}
this.consumed = function() {
if (this.bodyUsed) {
return new Promise.reject(new TypeError('Body already consumed'))
}
this.bodyUsed = true
return Promise.resolve(this.body)
}
return this
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册