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 安装svn网络有问题怎么办
    • ¥15 Python爬取指定微博话题下的内容,保存为txt
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥15 latex怎么处理论文引理引用参考文献