Angular 在rxjs 7中,在何处执行重试后出现的代码

Angular 在rxjs 7中,在何处执行重试后出现的代码,angular,rxjs,Angular,Rxjs,我正在使用HTTP拦截器&如果重试后RefreshTokenAPI失败,我想注销我的用户。 return this.authService.refreshToken().pipe( switchMap((token: any) => { console.log(token); this.isRefreshing = false; this.refreshTokenSubject.next(token.accessToken

我正在使用HTTP拦截器&如果重试后RefreshTokenAPI失败,我想注销我的用户。

    return this.authService.refreshToken().pipe(
      switchMap((token: any) => {
        console.log(token);
        this.isRefreshing = false;
        this.refreshTokenSubject.next(token.accessToken);
        return next.handle(this.addToken(req, token.accessToken));
      }),
      retry(3), //Tries the refreshToken() API if it returns with an error.
      catchError(error => {
      //If the refreshToken() API never returns a successful response, I want to Logout.
        this.authService.Logout();
        return throwError(error);
      }
    );

我的问题是,我做的错误正确吗?我只希望它在重试3次后仍然失败,但我担心它会在重试前捕获错误。

是的,它应该只有在
重试后才能工作。
。此外,您还可以将其设置为订阅错误回调,而不是
catchError
。 下面是对您的用例的模拟:

第一次订阅失败几次,但低于
重试
点-因此解决了问题

另一个在上面-因此发出
catchError
和错误回调