// catch 404 and forward to error handler
app.use(function (req, res, next) {
console.log('you have 404 on ', req.originalUrl);
next(createError(404));
});
app.use((err, req, res, next) => {
console.log('you have err on ', req.originalUrl, err);
if (err.status !== 403) return next();
res.send('403 error :: Invalid Token');
});
Use above code to debug where you make a mistake in my case one variable which is include in header is undefined after every load of any .JS file 🙂