Tuesday, November 1, 2022

Server error messages in Node.js

 //

app.use((err, req, res, next) => {
console.log(err);
err.statusCode = err.statusCode || 500;
err.status = err.status || 'error';
res.status(err.statusCode).json({
status: err.status,
message: err.message,
}); // {"status":"fail","message":"Page / not found!"}
next();
});

//

No comments:

Post a Comment