// 本地运行
async test() {
let resdata = {
code: "",
status: "",
msg: "",
data: []
}
const getdata = function(pagenum, i) {
return new Promise((resolve, reject) => {
if (pagenum == 0) {
reject()
}
resolve("data")
}).then(e => {
resdata.data.push(e)
console.log(resdata);
if (pagenum < i) {
return getdata(pagenum + 1, i)
} else {
return Promise.resolve()
}
}).catch(e => {
return Promise.reject({
code: -1,
status: "fail",
msg: "链接已过期",
data: []
})
})
}
await getdata(0, 10)
await getdata(10, 20)
await getdata(20, 30)
return resdata
}
// 调用方法
this.test().then(e => {
console.log(e);
}).catch(e => {
console.log(e);
})
// 输出
{
"code": -1,
"status": "fail",
"msg": "链接已过期",
"data": []
}
// 云函数运行
uniCloud.callFunction({
name: 'test',
data: {
url:url,
}
})
.then(res => {
console.log(res);
}).catch(err => {
console.log(err.message);
});
// 输出
[test]: [FUNCTIONS_EXECUTE_FAIL] [object Object]
1 个回复
DCloud_uniCloud_WYQ
reject出来的并不是返回结果而是错误