Most annoying experience of any app when it get crashed so basically it blocks the entire operation in expressJS
Lets fix this using the middleware, so even if the app has some issue will work continually and wont impact user on other part of the app
// An error handling middleware
app.use(function (err, req, res, next) {
console.log(err.message);
res.status(500);
res.json({ message: "Oops, something went wrong :(", error: err.message });
});
Thats it!
Let me know if you have any other suggestions :)
Top comments (0)