Javascript 如何修复未处理的节点PromisejectionWarning

Javascript 如何修复未处理的节点PromisejectionWarning,javascript,node.js,Javascript,Node.js,当一个用户试图发送一个简单的json,包括提供者的id和日期时,我会得到以下错误 UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object at Function.keys (<anonymous>) at Function.findAll (C:\Users\Usuario\Desktop\Studies\Go_Stack\modulo2\goBar

当一个用户试图发送一个简单的json,包括提供者的id和日期时,我会得到以下错误

UnhandledPromiseRejectionWarning: TypeError: Cannot
convert undefined or null to object
    at Function.keys (<anonymous>)
    at Function.findAll (C:\Users\Usuario\Desktop\Studies\Go_Stack\modulo2\goBarber\node_modules\sequelize\lib\model.js:1692:47)
    at Function.findOne (C:\Users\Usuario\Desktop\Studies\Go_Stack\modulo2\goBarber\node_modules\sequelize\lib\model.js:1924:17)
    at store (C:\Users\Usuario\Desktop\Studies\Go_Stack\modulo2\goBarber\src\app\controllers\AppointmentController.js:28:63)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
(node:19212) 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(). (rejection id: 1)
(node:19212) [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.

Appointment类中的findOne方法引发异常,而您不会在任何地方捕获它。您需要这样做:

let checkAvailability;
try {
  checkAvailability = await Appointment.findOne({
    where: {
      provider_id,
      canceled_at: null,
      date: hourStart,
    },
  });
} catch (err) {
  checkAvailability = false
}
使用
try catch
处理异常


签出等待引用:

约会类中的findOne方法引发异常,您无法在任何地方捕获它。您需要这样做:

let checkAvailability;
try {
  checkAvailability = await Appointment.findOne({
    where: {
      provider_id,
      canceled_at: null,
      date: hourStart,
    },
  });
} catch (err) {
  checkAvailability = false
}
使用
try catch
处理异常


签出等待参考:

请显示调用
存储
方法的代码部分。这就是您缺少错误处理的地方。请显示调用
store
方法的代码部分。这就是您缺少错误处理的地方。