How to handle errors in sequelize create

Asked

Viewed 237 times

0

Hello, I would like to know how I can treat possible errors when performing a create with sequelize for example considering the following insertion

 Livros.create({
            BK_TITLE: data.title,
            BK_GENRE: data.genre,
            BK_AUTOR: data.author,
            BK_OBS: data.obs
        })

Is there any way to identify if he successfully entered or presented error for example the lack of an input or something like that so I can handle in my front-end

1 answer

1


One way to do this would be to change the create to stay this way:

Livros.create({
	BK_TITLE: data.title,
	BK_GENRE: data.genre,
	BK_AUTOR: data.author,
	BK_OBS: data.obs
}).then(function(item){
	console.log(item); //Item gravado
}).catch(function (err) {
	console.log(err); //Erro ao gravar
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.