问题
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();
});
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.
Update
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);
}
});
回答1:
The issue was fixed in firebase-functions v3.9.1. Alternatively you could downgrade to v3.8.0.
See https://github.com/firebase/firebase-functions/issues/757#issuecomment-673080726
回答2:
I just got the same error on a new project. Took me a few hours to realize I forgot to initialize firebase admin after I imported it in my functions
import * as admin from 'firebase-admin';
admin.initializeApp();
来源:https://stackoverflow.com/questions/63349136/unhandled-error-gets-thrown-in-firebase-cloud-functions