Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda