如何处理减速器内的错误? [英] How to handle errors inside reducers?

查看:69
本文介绍了如何处理减速器内的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有loggerService,我需要捕获reducer中的所有错误并将其通过我的服务发送到服务器.

I've my loggerService and I need to catch all errors in reducer and send it via my service to the server.

我该怎么办?我知道reducer应该是一个纯函数,但是还有什么想法吗?

How can I do it? I know that reducer should be a pure function, but still any ideas?

我需要添加reduser try catch

I need to add in reduser try catch

    case actions.GAMES_LOADED{
       ......
       try{}
       catch(err){
       this.loggerService.error(err);
    }
}

或者在减速器中扔一些东西,然后放在某个地方...

Or maybe throw something in reducer and catch it in some place...

非常感谢

推荐答案

简短的回答:您不知道.

为什么?-减速器仅负责更新商店,它应该执行任何业务逻辑或验证数据-到达商店的任何数据都应该是已经有效,只能从商店中进行存储/更新/删除.

Why? - The reducer is only responsible for updating the store, it should not perform any business-logic or validate data - any data that reaches the store should be already valid and just be stored/updated/removed from the store.

可能的解决方案:您应该在 效果 或某些负责获取/创建数据的服务.

这篇关于如何处理减速器内的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆