我正在使用 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/