wakeup
wakeup

Reputation: 67

Sequelize not showing syntax errors

I'm doing a simple update with Sequelize, but if I put an unexisting field it doesn't show any error in console.

ret is 0, but I would like to diferrenciate when no fields are update because of the "where" filter, and when there is a syntax error and where is the error. I guess I have to active any option in sequelize. Thanks

 const ret = await models.Users.update(
        { notexistingfield: newpass },
        { where: { user: 'username' } }
    );

   if (ret) res.status(200).send('ok');
   else res.status(404).send('Error');

Upvotes: 0

Views: 372

Answers (1)

Rahul
Rahul

Reputation: 1123

Use Try Catch

try {
    const ret = await models.Users.update(
        { notexistingfield: newpass },
        { where: { user: 'username' } }
    );

   if (ret) res.status(200).send('ok');
   else res.status(404).send('Error');
} catch(error) {
    // Any syntex or database errors
    console.log(error)
    res.status(400).send('Error');
}

Upvotes: 1

Related Questions