更改的请求不适用于6号角

时间:2019-04-12 08:21:19

标签: angular6 rxjs6

我有以下函数,该函数调用刷新服务以获取新令牌以进行授权:

private handle401Error(request: HttpRequest<any>, next: HttpHandler) {
  if(!this.isRefreshingToken) {
    this.isRefreshingToken = true;
    return this.authService.refreshToken()
    .subscribe((response)=> {
      if(response) {
        const httpsReq = request.clone({
          url: request.url.replace(null, this.generalService.getUserId())
        });
        return next.handle(this.addTokenToRequest(httpsReq, response.accessToken));
      }
      return <any>this.authService.logout();
    }, err => {
      return <any>this.authService.logout();
    }, () => {
      this.isRefreshingToken = false;
    })
  } else {
    this.isRefreshingToken = false;
    return this.authService.currentRefreshToken
    .filter(token => token != null)
    .take(1)
    .map(token => {
      return next.handle(this.addTokenToRequest(request, token));
    })
  }
}

当响应未定义且请求返回时,它不会调用新请求

1 个答案:

答案 0 :(得分:0)

好吧,关于载体的引用如下:

enter image description here

但是我仍然遇到一个问题,该请求不调用新请求,当我刷新页面时,它会使用新令牌提供数据,就像以前有未经授权的错误一样。