- 当前 Bug 的表现(可附上截图)
- 预期表现
- 复现路径
- 提供一个最简复现 Demo
偶现调用云函数出错,错误如下图。出错后再重复调用几次又能正常调用,直接对云函数进行测试,并没有发现异常。
以下是云函数的代码
const https = require('https');
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
console.log(event);
console.log(context);
let result = await getAnimal(event.imgbase64);
console.log(result);
return { result };
}
function getAnimal(imgbase64) {
return new Promise((resolve, reject) => {
var accessToken ='
24.e3bb433cd200255ac99826a61b9e9d52.2592000.1554562978.282335-15699423
';
let postData = qs.stringify( {
image: imgbase64,
baike_num: "1"
});
let options = {
hostname: 'aip.baidubce.com',
path: '/rest/2.0/image-classify/v1/animal?access_token=' + accessToken,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
let req = https.request(options,
function (res) {
res.on('data', (data) => {
resolve(JSON.parse(data.toString()));
});
res.on('error', (err)=>{
reject(err);
});
}
);
req.write(postData);
req.end();
});
}