Firebase Cloud Functions中引发未处理的错误 [英] Unhandled Error gets thrown in Firebase Cloud Functions

查看:69
本文介绍了Firebase Cloud Functions中引发未处理的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Firebase Cloud Functions, and in one of my projects I have a simple function that looks like the following:

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.但是更大的问题是引发的错误是我在该项目中遇到的所有错误的原因:

I know where the error is through other methods and why it is, I'm using an invalidStudentPath. But the bigger issue is that the error that gets thrown is this for all of my errors in this project:

Unhandled error function error(...args) {
   write(entryFromArgs('ERROR', args));
} 

如何获取实际错误而不是此晦涩的消息?感谢您的帮助.

How can I get the actual error instead of this obscure message? Thanks for any help.

更新

我现在找到了解决方法.目前,我将整个函数包装在一个如下所示的try catch块中:

I have found a workaround for now. Currently I'm wrapping my whole function in a try catch block that looks like this:

exports.responseGiven = functions.https.onCall(async (data, context) => {
  try {
    ...
  } catch (e) {
    console.log('There was an error');
    console.log(e);
  }
});

推荐答案

此问题已在 firebase函数v3.9.1 .或者,您可以降级到v3.8.0.

The issue was fixed in firebase-functions v3.9.1. Alternatively you could downgrade to v3.8.0.

请参见 https://github.com/firebase/firebase-函数/问题/757#issuecomment-673080726

这篇关于Firebase Cloud Functions中引发未处理的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆