593042433 2017-07-06 02:06 采纳率: 0%
浏览 2254

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报错,不明白这样写为什么报错,求大神指点谢谢!

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料