【问题标题】:Nodejs Runs Promise but still Undefined is not a functionNodejs 运行 Promise 但仍然 Undefined 不是函数
【发布时间】:2016-12-14 16:54:40
【问题描述】:

我面临一个无法调试的特殊问题。 TypeError: My code is returned function is undefined which end the API call 但我查看了日志和断点,在 API 以错误结束后,它继续执行相同的 then 函数。

这怎么可能。

我正在使用 nodejs/express/sequelizejs

models.Holdings.update(obj,{
      where:{
             id: obj.id
            }
}).then().catch()

【问题讨论】:

  • 将函数传递给 then 并 catch。
  • @danh:如何。我无法理解你的意思

标签: javascript node.js express sequelize.js


【解决方案1】:

Then 和 catch 旨在提供在解决和错误时(分别)执行的函数。

models.Holdings.update(obj,{
      where:{
             id: obj.id
            }
}).then(function(result) {
    console.log(result);
}).catch(function(error) {
    console.log(error);
});

【讨论】:

  • 是的。但我的问题是我的代码将首先捕获错误块,然后几秒钟后进入 then 块。这很奇怪。如果它已经通过了 catch 块,那么它以后如何进入 then 块。
  • 我不认为它可以。但是 OP 代码显示没有块传递给任何一个。如果该代码不存在,它就不能去 then 或 catch 代码
猜你喜欢
  • 2012-12-25
  • 2023-03-15
  • 2021-09-16
  • 1970-01-01
  • 2019-06-04
  • 1970-01-01
  • 2011-10-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多