Error Handling Middleware

 has 4 psrameters

app.get("/err", (req, res) => {
  abcd = xyz;
});
app.use((err, req, res, next) => {
  console.log("-----ERROR------");
 
});



HERE ,EVEN IF WE HAVE DECLARED THE PATH("/ERR") IT CANNOT BE ACCESSED.

TO ACCESS IT WE NEED TO USE next().

IF WE CALL next() it will call for non-error middleware handlers.


app.use((err, req, res, next) => {

  console.log("-----ERROR------");
  next();
});


WE NEED TO USE next(err)  it includes error handlers middlewares too.

app.use((err, req, res, next) => {
  console.log("-----ERROR------");
  next(err);
});








Comments

Popular posts from this blog

DATABASE RELATIONSHIPS

ROUTING (GET /) home route

Query Strings