Skip to content

Not Found Errors — Handling Missing Resources

DodaTech Updated 2026-06-28 1 min read

In this tutorial, you will learn about Not Found Errors. We cover key concepts, practical examples, and best practices to help you master this topic.

Not-found errors indicate the requested resource does not exist, returning 404 with information about what was not found and possible alternatives.

Implementation

app.get("/api/users/:id", async (req, res) => {
  const user = await findUser(req.params.id);
  if (!user) {
    return res.status(404).json({
      status: 404,
      error: "not_found",
      message: "User not found",
      resource: "User",
      resourceId: req.params.id,
      requestId: req.id
    });
  }
  res.json(user);
});

Best Practices

Include the resource type and identifier in the response so clients can identify which specific request failed. Do not expose whether the resource ever existed (security concern for some APIs).

Common Mistakes

  1. Returning empty 200 — Return 404, not 200 with null data.
  2. No resource identification — Not telling which resource was not found.
  3. Returning 500 — Missing resources are client errors, not server errors.

Practice Questions

  1. What status code indicates a missing resource?
  2. What information should a 404 response include?
  3. When might you avoid revealing whether a resource exists?

What's Next

In the next lesson, you will learn conflict error handling.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro