One failed request takes down my whole Express server
Asked by Samuel Okafor · 456 views · 2 replies
If the database is briefly unreachable, one request fails and then the entire Node process exits:
[UnhandledPromiseRejection: This error originated either by throwing
inside of an async function without a catch block, or by rejecting a
promise which was not handled with .catch().]
The route is just:
app.get("/users/:id", async (req, res) => {
const user = await db.findUser(req.params.id);
res.json(user);
});
Shouldn't Express catch errors in route handlers?