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
- Returning empty 200 — Return 404, not 200 with null data.
- No resource identification — Not telling which resource was not found.
- Returning 500 — Missing resources are client errors, not server errors.
Practice Questions
- What status code indicates a missing resource?
- What information should a 404 response include?
- When might you avoid revealing whether a resource exists?
What's Next
In the next lesson, you will learn conflict error handling.
← Previous
Authentication Errors — 401 and 403 Responses
Next →
Conflict Errors — Handling Duplicate and State Conflicts
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro