我遇到了 Angular 2 和 ngrx/store 的特定代码状态,我的应用程序完全中断(路由不工作,数据不出现,路由回到前一个,以及所有其他类型的可能的灾难),但我快用完了关于如何调试商店周围发生的事情的想法。redux dev-tools 是一个很棒的工具,但它似乎无法捕获错误。
我.catch在我的选择器、效果和.subscribe()语句之前放置了语句,尝试了两种变体:
return state$.select(state => state.user)
.map(user => user.collection)
.catch((error, caught) => {
console.log('error getCollection');
return caught;
});
Run Code Online (Sandbox Code Playgroud)
和
return state$.select(state => state.user)
.map(user => user.collection)
.catch((error) => {
console.log('error getCollection');
return Observable.throw(error);
});
Run Code Online (Sandbox Code Playgroud)
控制台仍然保持沉默。我只是不相信除了商店之外不会有任何其他“单一的错误来源”。
此代码不会为我捕获错误。应该是?:
.do(() => {
Observable.throw('fake error');
})
.catch(error => {
console.error(error);
return Observable.throw(error);
});
Run Code Online (Sandbox Code Playgroud)
谁能告诉我如何调试整个商店使用的可观察对象?
使用 .do() 记录流 - 这将修复它
您需要通过 RXJS 导入添加 do 运算符。
return state$
.do(() => { // log here } )
.select(state => state.user)
.map(user => user.collection)
.catch((error, caught) => {
console.log('error getCollection');
return caught;
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3757 次 |
| 最近记录: |