gpt4 book ai didi

redux-observable 无法从发出的 Action 中捕获错误,错误停止 Action 流

转载 作者:行者123 更新时间:2023-12-02 02:48:36 24 4
gpt4 key购买 nike

如果 js 错误是由于 redux-observable 史诗发出的 Action 导致的,那么它会阻止所有史诗监听新 Action 。这非常糟糕,因为在前端它仍然看起来好像应用程序正在运行,但在后台没有任何内容被保存。

我尝试在我的史诗中捕获错误,但出于某种原因,它没有捕获由生成的发出操作引起的错误(请参见此处的示例:https://stackblitz.com/edit/redux-observable-playground-qtughj?file=ping-pong.js)

我认为升级到版本 1.0.0 redux-observable 可以解决这个问题,但不幸的是它仍然存在。

有什么方法可以捕获由 redux-observable 发出的操作引起的错误?

问题不同于 this question由于错误是在史诗发出后发生的 reducer 中触发的,因此它的输出 redux 操作因此在可观察链中使用 .error 捕获它不起作用(参见 example above 的演示).

谢谢!

最佳答案

redux-observable Github repo 中讨论了这个问题之后最安全的解决方案似乎是创建一些自定义的 Redux 中间件来阻止错误一直冒泡回到根史诗,例如

const store = createStore(rootReducer,
applyMiddleware(epicMiddleware, store => next => action => {
try {
next(action);
} catch (e) {
setTimeout(() => {
throw e;
});
}
})
);

关于redux-observable 无法从发出的 Action 中捕获错误,错误停止 Action 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53164276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com