Попытка обновить таблицу - Ошибка: необработанное отклонение обещания node.js - PullRequest
0 голосов
/ 09 марта 2020

Я пытаюсь обновить пользователя с помощью хешированного пароля при запуске приложения. Поэтому я написал это в app. js:

try {
  bcrypt.hash("ADMIN", saltRounds, async function(err, hash) {
    queryUpdate = await Utilisateur.query().patch({
        MOTPASS: hash
    }).where('NOGENE', 4219)
    .catch(console.log('err'));
 });
} catch (err) {
  errorDbHandler.sendErrorHttp(err, res);
}

И я получил эту ошибку:

(node:6800) UnhandledPromiseRejectionWarning: TypeError: Utilisateur.query is not a function
    at D:\Project\***\backend\app.js:48:37
(node:6800) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:6800) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

1 Ответ

0 голосов
/ 09 марта 2020

используйте этот код для отлова ошибки:

try {
  bcrypt.hash("ADMIN", saltRounds, async function(err, hash) {
    try {
      queryUpdate = await Utilisateur.query().patch({
        MOTPASS: hash
      }).where('NOGENE', 4219);
    } catch (e) {
      console.log(e);
    }
 });
} catch (err) {
  errorDbHandler.sendErrorHttp(err, res);
}

вы пытались смешать "then (). Catch ()" с "await", что не будет работать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...