按照文档里面写法,执行如下云函数,目的是更新文档的浏览数量
const cmd = db.command;
const collection = db.collection('goods');
let data=await collection.get();
data.data.map(async (item) => {
return await collection.doc(item._id).update({
visite: cmd.inc(1)
});
});
一直提示错误信息
[goodsInfo/ac14109b1588403839929731174/10ms/ERROR] (node:10) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error
[goodsInfo/ac14109b1588403839929731174/10ms/ERROR] (node:10) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
然后按照网上的说法,可以吧这个异常捕获到
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at:', p, 'reason:', reason);
// application specific logging, throwing an error, or other logic here
});
下面是捕获到的信息
[goodsInfo/ac1412111588404467134168576/7ms/DEBUG] Unhandled Rejection at: Promise {
<rejected> { Error: errCode: | errMsg: Response timeout for 5000ms, POST https://api.bspapp.com/server -1 (connected: true, keepalive socket: false, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
at e.then.catch.e (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:1025)
at <anonymous>
errMsg: 'Response timeout for 5000ms, POST https://api.bspapp.com/server -1 (connected: true, keepalive socket: false, socketHandledRequests: 1, socketHandledResponses: 0)\nheaders: {}' } } reason: { Error: errCode: | errMsg: Response timeout for 5000ms, POST https://api.bspapp.com/server -1 (connected: true, keepalive socket: false, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
at e.then.catch.e (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:1025)
at <anonymous>
errMsg: 'Response timeout for 5000ms, POST https://api.bspapp.com/server -1 (connected: true, keepalive socket: false, socketHandledRequests: 1, socketHandledResponses: 0)\nheaders: {}' }
1 个回复
最佳回复
龙雨溪
https://segmentfault.com/a/1190000020809964