angular - 如何在 catchError 代码块中使用代码
问题描述
我不知道正确的语法,如何在 catchError 中使用代码块?
this.budgetService.getBudgetDays(this.startDate, this.finishDate)
.pipe(
catchError(res => self.budgetTestService.getBudgetDates(self.startDate, self.finishDate))
)
.subscribe(res => {
console.log('Response = ', res);
self.timelineBudgetDates = self.processDates(res);
//self.timelineBudgetDates = res;
});
所以我想使用这样的东西,我可以为timelineDates分配一个值。
.pipe(
catchError(self.timelineDates = self.budgetTestService.getBudgetDates(self.startDate, self.finishDate)
// more code...
)
)
解决方案
尝试使用这个
.pipe(
catchError(err => {
self.timelineDates = self.budgetTestService.getBudgetDates(self.startDate, self.finishDate);
console.error(err.message);
console.log("Error is handled");
return throwError("Error thrown from catchError");
})
// more code...
)
从这里了解详细信息https://www.concretepage.com/angular/angular-catcherror
推荐阅读
- java - 如何使用 java sdk 创建具有权限的 aws 角色?
- nginx - 将第二个域重定向回主域上的特定位置
- c++ - 在 C++ 中,如何在派生类中重用静态成员函数?
- r - 如何在r中的一个新行中汇总多行
- c# - ASP.NET Core 3.0 Identity Server 4 (4.0.0) SecurityTokenInvalidAudienceException:IDX10214:观众验证失败。观众:“空”
- spring-boot - JPA findBy 查询创建加自定义参数
- java - 单独的 java 文件中枚举的常量特定类体
- firebase - Flutter 中的 Firestore Throw Handle Exception Error 崩溃
- c# - C#抓取项目点击事件问题
- c# - Protobuf-net 是否有计划包括验证?