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

138
Visualizações
Catching Error With Custom Rest API For FireStore Javascript

I have been watching a tutorial on making a Rest API for Firestore which appears to work but I cannot figure out how to catch an error.

The code below basically uses an end point to retrieve a document id from the firestore database. The client uses javascript fetch to call the API.

I am trying to workout how to return something back to the client from the API if the document id is not there. I thought I might get a 404 status returned but I always get status 200.

This is the API code I used

app.get("/api/read/:id", (req, res) => {

(async () => {

    try {

        const document = db.collection("users").doc(req.params.id);
        let product = await document.get();
        let response = product.data();

        return res.status(200).send(response);

    } catch (error) {
        console.log(error);
        return res.status(500).send(error);
    }

})();

})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm fairly certain that the 404 message is for the server itself not being found (though I do need to brush up on my error codes).


However, if you're looking to check to see if a document exists there's a command specifically for that demonstrated in the examples in the firebase docs

about 4 years ago · Juan Pablo Isaza Relatório
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