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

140
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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