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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚拟机打包apk出现错误
    • ¥30 最小化遗憾贪心算法上界
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝