承诺错误传播和捕获

时间:2015-08-12 16:11:14

标签: promise bluebird

我似乎无法捕获TypeError我自己,无论我将catch块放置在蓝鸟的哪个地方......它似乎总是被蓝鸟的捕获所有政策,但不是我自己的捕获块:

Unhandled rejection TypeError: Cannot call method 'storeConfigModel' of null
...
  at tryCatcher (.../node_modules/bluebird/js/main/util.js:24:31)

开发人员可能会出现哪些常见错误会导致这种情况?

这是我的代码段:

      .then(function(storeModelInstance) {
        log('print object for storeModelInstance: ', storeModelInstance);
        var storeConfigInstance = storeModelInstance.storeConfigModel(); // FAILS HERE
        log('print object for storeConfigInstance: ', storeConfigInstance);
        return Promise.resolve([reportModelInstance, storeModelInstance, storeConfigInstance]);
      })
      .catch(TypeError, function(error) {
        // WHY doesn't this pick up on TypeError in the above block?
        return Promise.reject(error);
      })

1 个答案:

答案 0 :(得分:2)

可能已被拾取,但您随后会"抛出"它再次:

return Promise.reject(error);