Where to handle the error in a sequelize ORM query statement?

If you want to handle the specific error, attach a .catch handler

models.Item.create({
  title : req.body.title,
  UserId : req.body.UserId
}).then(function(item){
  res.json({
    "Message" : "Created item.",
    "Item" : item
  });
}).catch(function (err) {
  // handle error;
});

If you want to handle errors more generally (i.e. show a nice error message, instead of killing your server, you might want to have a look at unhandledexception

https://nodejs.org/api/process.html#process_event_uncaughtexception

If you are using express, it also contains some error handling facilities http://expressjs.com/en/guide/error-handling.html

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)