Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda