Firebase异步/等待弃用警告:弃用未处理的承诺拒绝

时间:2019-05-01 14:58:35

标签: firebase firebase-realtime-database promise async-await google-cloud-functions

我正在尝试使用带有Async / Await的功能来建立与Firebase实时数据库的简单连接以减少代码,即使您使用try / catch包装代码,它仍然会引发以下错误。

exports.createBlogPost = functions.https.onRequest(async (req, res) => {
  try {
    cors(req, res, () => { });
    const response = req.body;
    response.createDate = new Date();
    const snapshot = await admin.database().ref(BLOG_POSTS).push(response);
    console.log("SNAP", snapshot.getKey());
    response.id = snapshot.getKey();
    res.send(response);
  } catch (e) {
    res.status(500).send(e);
  }
});

它在数据库中创建实例,但是我收到以下警告:

info: SNAP -LdnpewpwEz9EOkAA05H

error: (node:13656) UnhandledPromiseRejec: Unhandled promise rejections are deprecated. 
In the future, promise rejectiontionWarning: Unhandled promise rejection. Node.js process with a non-zero exit code. 
This error originated either by throwingon completed successfully inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)(node:13656) 
[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.info: Execution took 1035 ms, user function completed successfullyerror: Function worker killed by signal: SIGTERM

0 个答案:

没有答案