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

137
Views
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 answers
Answer question

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 Report
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!