如何解决Firebase 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
,我在一个新项目中遇到了同样的错误。花了我几个小时才意识到我在将Firebase admin导入函数后忘记了初始化它。
import * as admin from 'firebase-admin';
admin.initializeApp();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。