u013913207
593042433
采纳率0%
2017-07-06 02:06 阅读 2.1k

Nodejs,Promise使用时在then中返回Promise报错,不明白这样写为什么报错

var wechat = new Wechat()
var data = yield wechat('image', __dirname + '\.5.jpg', false)
Wechat.prototype.uploadMaterial = function(type, filePath, isPermanent){
var that = this
var url = api.temporary.upload
var form = {
media: fs.createReadStream(filePath)
}

that
    .fetchAccessToken()
    .then(function(data){
            console.log(data)
            if(!isPermanent){
                url +=  'access_token=' + data.access_token + '&type=' + type
            }
            return new Promise(function(resolve, reject){
                request({method:'POST', uri: url, formData: form, json:true})
                .then(function(response){
                    var _data = response.body
                    resolve(_data)
                })
            })
})

}


报错信息如下

TypeError: You may only yield a function, promise, generator, array, or object, but the following object was passed: "
undefined"
at next (H:\study\com\node_modules\co\index.js:101:25)
at onFulfilled (H:\study\com\node_modules\co\index.js:69:7)
at H:\study\com\node_modules\co\index.js:54:5
at Object.co (H:\study\com\node_modules\co\index.js:50:10)
at Object.toPromise (H:\study\com\node_modules\co\index.js:118:63)
at next (H:\study\com\node_modules\co\index.js:99:29)
at onFulfilled (H:\study\com\node_modules\co\index.js:69:7)
at tryCatcher (H:\study\com\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (H:\study\com\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (H:\study\com\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromiseCtx (H:\study\com\node_modules\bluebird\js\release\promise.js:606:10)
at Async._drainQueue (H:\study\com\node_modules\bluebird\js\release\async.js:138:12)
at Async._drainQueues (H:\study\com\node_modules\bluebird\js\release\async.js:143:10)
at Immediate.Async.drainQueues (H:\study\com\node_modules\bluebird\js\release\async.js:17:14)
at tryOnImmediate (timers.js:639:5)
at processImmediate as _immediateCallback

Nodejs,Promise使用时在then中返回Promise报错,不明白这样写为什么报错,求大神指点谢谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

相关推荐