首页 > 解决方案 > 如何在 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...

  )
)

标签: angularrxjs

解决方案


尝试使用这个

.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


推荐阅读