Home > Back-end >  Must we manually log errors in Firebase Cloud Functions or will they log automatically?
Must we manually log errors in Firebase Cloud Functions or will they log automatically?

Time:11-14

I have this cloud function currently deployed. It returns a promise as required by Firebase to terminate the function.

exports.userDidSignOut = functions.https.onCall((data) => {
    const userId = data.userId;
    const settingsUpdate = {
        "fcmToken": null,
    };
    const promise = admin.firestore().collection("user-settings").doc(userId).update(settingsUpdate);

    return promise
});

However, will this log errors on the console automatically? Or must I log them manually (as below)?

exports.userDidSignOut = functions.https.onCall((data) => {
    const userId = data.userId;
    const settingsUpdate = {
        "fcmToken": null,
    };
    const promise = admin.firestore().collection("user-settings").doc(userId).update(settingsUpdate);

    promise.then(() => {
        return null;
    }, (reason) => {
        console.log(reason);
        return null;
    });
});

And is it necessary to return null in the failure function to terminate the cloud function or is printing to the console sufficient?

CodePudding user response:

There's an entire documentation page on handling errors in Cloud Functions. From there:

Uncaught exceptions produced by your function will appear in Error Reporting.

So you don't have to do this yourself, although you can of course always do so to add additional context around the error.

  • Related