I'm developing an API in TypeScript with NodeJS and MariaDB; when I do an operation with the bank, right below I have a if to check if an error has occurred.
productDao.save({name:"Notebook Dell", price:"5000"}, function(err, res){
if(err){
//Código para caso algo dê errado.
}else{
//Código se tudo der certo.
}
})
The case is: Can I use promises in an API? I would like it to look something like this:
productDao.save({name:"Notebook Dell", price:"5000"})
.then(res => {
//Caso tudo dê certo.
})
.catch(err => {
//Caso algo dê errado.
})
However, I wonder, is the default promise ideal for an API? What are the possible complications? What would be the disadvantages and advantages over this architecture in an API ?