I am using Sequelize ORM in Node/Express.
I have two tables, User and Item. Item has a foreign key linked to UserId.
When I try to create an Item with a UserId that is invalid (not present in Users table) a SequelizeForeignKeyConstraintError is thrown and leads to crashing of the application due to unhandled.
The problem I have is this:
Where do I handle the error?
Here is my code.
.post(function(req,res){
models.Item.create({
title : req.body.title,
UserId : req.body.UserId
}).then(function(item){
res.json({
Message : Created item.,
Item : item
});
});
});