Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
How to decipher between different Firebase errors in single Cloud Function catch block?

I have a Firebase Cloud Function that performs two async tasks (create user by Authentication and batch write by Firestore) with a single catch block for all errors. My question is how can I decipher if the error is thrown from Authentication or from Firestore in the catch block before I throw the HTTPS error to the client?

exports.createUser = functions.https.onCall((data, _context) => {
    const email = data.email;
    const password = data.password;
    const birthday = data.birthday;
    const name = data.name;

    return admin.auth().createUser({
        email: email,
        password: password,
    })
    .then((userRecord) => {
        const userId = userRecord.uid;
        const db = admin.firestore();
        const batch = db.batch();
        const testDocRef1 = db.collection("test1").doc(userId);
        const testDocRef2 = db.collection("test2").doc(userId);

        batch.create(testDocRef1, {name: name, email: email});
        batch.create(testDocRef2, {name: name, birthday: birthday});

        return batch.commit().then(() => {
            return Promise.resolve({"userId": userId});
        });
    })
    .catch((error) => {
        // how can I decipher which async task this error came from?
        throw new functions.https.HttpsError("unknown", "Refer to details for error specifics.", error);
    });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!