Tuesday, 1 September 2020

Firebase functions throws uncatchable error

I'm calling the following Firebase function:

exports.getUserRecord = functions.https.onCall(async (data, context) => {
    try {
        //This successfully logs an existing uid in firestore, it should be retrievable
        console.log(context.auth.uid)

        const doc = admin.firestore().collection('user').doc(context.auth.uid);
        const res = await doc.get() //Isolated it down to this line that is failing
        return res
    } catch (err) {
        console.log(err)
        throw new functions.https.HttpsError('unavailable', 'some error message');
    }
});

When calling this function I receive the following error on the client:

POST https://us-central1-xxx-xxx.cloudfunctions.net/getUserRecord 500
Uncaught (in promise) Error: INTERNAL

On the server logs I see this error:

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

I am wondering how there is an error that neither of my error logging lines are picking up, and also what is causing this error?

EDIT: I have also tried logging other things within my catch block but they do not appear, it seems there is an error but the code does not enter the catch block somehow.

I have also seen this post which seems to suggest this was an issue that was patched in firebase-functions 3.9.1, but I have upgraded and still have this issue



from Firebase functions throws uncatchable error

No comments:

Post a Comment