0

我试图找到一种仅在给定的 rxjs 链中没有错误的情况下运行某些代码的方法。考虑以下问题,NO_ERROR_OCCURED_RUN_HAPPY_PATH_CODErxjs 中是否有类似人工运算符的东西?

private wrap(obs: Observable<any>): Observable<any> {
  return of(1).pipe(
    tap(() => this.spinner.startSpinner()),
    mergeMap(() =>
      obs.pipe(
        NO_ERROR_OCCURED_RUN_HAPPY_PATH_CODE(() => this.generic_success_popup()),
        catchError(this.handleError),            
      )
    ),
    finalize(() => this.spinner.stopSpinner())
  );
}
4

1 回答 1

0

基本上,如果管道上没有抛出错误,几乎所有的操作符都会被调用,除了finalize

  obs.pipe(
    tap(_=>console.log('no error, will run'),
    // throw some error
    map(_=>throwError('some error'),
    finalize(_=>console.log('will be called when there is error or upon observable complete')),
    tap(_=>console.log('this will not run')),
    catchError(this.handleError),           
  )
于 2020-04-05T13:39:05.307 回答