node.js - Firebase Cloud Functions 中抛出未处理的错误

标签 node.js firebase express google-cloud-functions

我正在使用 Firebase Cloud Functions,在我的一个项目中,我有一个简单的函数,如下所示:

exports.responseGiven = functions.https.onCall(async (data, context) => {
  if (!context.auth) {
    throw new functions.https.HttpsError(
        'permission-denied',
        'Must be an user to execute this action'
    );
  }

  const studentPath = data.studentPath;
  const eventPath = data.eventPath;
  const isUpdating = data.isUpdating;

  const studentDoc = await admin.firestore().collection('students').doc('studentPath').get();
  const eventDoc = await studentDoc.ref.collection('entries').doc(eventPath).get();
});
我通过其他方法知道错误在哪里以及为什么会这样,我使用的是 invalidStudentPath。但更大的问题是抛出的错误是我在这个项目中的所有错误:
Unhandled error function error(...args) {
   write(entryFromArgs('ERROR', args));
} 
我怎样才能得到实际的错误而不是这条晦涩的消息?谢谢你的帮助。
更新

我现在找到了解决方法。目前,我将整个函数包装在一个 try catch 块中,如下所示:
exports.responseGiven = functions.https.onCall(async (data, context) => {
  try {
    ...
  } catch (e) {
    console.log('There was an error');
    console.log(e);
  }
});

最佳答案

该问题已在 firebase-functions v3.9.1 中得到修复.或者,您可以降级到 v3.8.0。
https://github.com/firebase/firebase-functions/issues/757#issuecomment-673080726

关于node.js - Firebase Cloud Functions 中抛出未处理的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63349136/

相关文章:

javascript - 编码包含 Node.js 缓冲区的 MessagePack 对象

javascript - Firebase:如何将虚 URL 添加到云功能?

sql-server - 在 SQL 2008 中使用 Sequelize.js 进行分页(不支持 FETCH)

node.js - 当我将数据从 index.js 传递到 index.ect 时,我无法在 Node.js 上显示模型值

node.js - 带有 nginx 负载均衡器问题的 Socket.IO 集群

javascript - 如何使用嵌套数组循环响应对象

ios - 每当应用程序在 iOS 中启动时,注册 token 是否会刷新?

javascript - 如何使用 Javascript 从多个 firebase 数据库中获取数据?

javascript - 如何在 sails.js 中创建动态策略

node.js - Nodejs 内存限制为 512 MB