QQ375776626
QQ375776626
  • 发布:2020-06-18 15:31
  • 更新:2020-06-18 15:34
  • 阅读:718

云函数中 reject 返回用 catch 不能捕获吗?

分类:uniCloud

云函数中 reject 返回用 catch 不能捕获吗?

2020-06-18 15:31 负责人:无 分享
已邀请:
QQ375776626

QQ375776626 (作者) - 80后

云函数代码 test

exports.main = async function() {  
    return new Promise((resolve, reject) => {  
        setTimeout(() => {  
            reject('error')  
        }, 1000)  
        resolve('success')  
    })  
}

客服端

uniCloud.callFunction({  
    name: 'test'  
})  
.then(res => {  
    console.log(res) //期望值 success  
})  
.catch(res => {  
    console.log(res) //期望值 error  
})
  • DCloud_uniCloud_WYQ

    去掉你的resolve('success') ,你这个代码里面直接就执行resolve了,另外reject应该传入一个Error对象这样比较符合标准

    2020-06-19 11:51

该问题目前已经被锁定, 无法添加新回复