Dva: effect返回promise catch 捕捉不到错误

Created on 2 Apr 2018  ·  9Comments  ·  Source: dvajs/dva

catch并捕捉不到错误
只有在effect 用try catch 才能捕捉到

  dispatch({
      type: 'product/list',
    })
  .then((data) => {
    console.log(data);
  })
  .catch((e) => {
    console.log(e);
  });
question wontfix

Most helpful comment

没有全局onError ,不过现在有一个hack的写法

const app = dva({
  onError(){}
});

这样写dispatch 调用的时候能够catch 到错误

All 9 comments

try {
  await dispatch(...);
} finally {
}

也发现这个问题,catch和finally都没执行,在effect里面可以try catch,但是重新throw之后也没法在dispatch捕捉

是不是定义了 onError hook,被 onError catch 掉了?

有问题再 reopen 。

没有全局onError ,不过现在有一个hack的写法

const app = dva({
  onError(){}
});

这样写dispatch 调用的时候能够catch 到错误

同样问题,必须得用@hnsylitao 说的hack

dva版本 2.3.1

关注,dispatch的捕错与onError中e.preventDefault的冲突实在恼人。

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@hnsylitao 感谢

Was this page helpful?
0 / 5 - 0 ratings