title: Angular 10: repeat the same http request after obtaining the refresh token
body: <p>I am trying to achieve the following in my HTTP calls</p>
  <ol>
  <li>If an API request returns 401  then call the refresh token endpoint to get the token.</li>
  <li>Retry the same HTTP call with the updated token</li>
  </ol>
  <p>Here is the relevant code</p>
  <pre><code>// this method invoke when the HTTP interceptor returns 401 status code
  
  handle401(request: HttpRequest&lt;any&gt;, next: HttpHandler) {
      if (!this.refreshTokenInProgress) {
        this.refreshTokenInProgress = true;
        this.refreshTokenSubject.next(null);
        return this.getToken((data: any) =&gt; {
          this.refreshTokenInProgress = false;
          this.refreshTokenSubject.next(data);
          request = request.clone({ headers: request.headers.set('Authorization', `Bearer ${data}`) });
          return next.handle(request);
        })
      } else {
        return this.refreshTokenSubject.pipe(
          filter(token =&gt; token != null),
          take(1),
          switchMap((accessToken) =&gt; {
            request = request.clone({ headers: request.headers.set('Authorization', `Bearer ${accessToken}`) });
            return next.handle(request);
          })
        );
      }
    }
  </code></pre>
  <p>Obtain the refresh token</p>
  <pre><code>getToken(cb: any) {
      let poolData = {
        UserPoolId: environment.cognitoUserPoolId, // Your user pool id here
        ClientId: environment.cognitoAppClientId // Your client id here
      };
      let userPool = new CognitoUserPool(poolData);
      let cognitoUser = userPool.getCurrentUser();
      cognitoUser?.getSession((err: any, session: any) =&gt; {
        const refresh_token = session.getRefreshToken();
        cognitoUser?.refreshSession(refresh_token, (refErr, refSession) =&gt; {
          
          const userToken = localStorage.getItem('token');
          cb(userToken);
        });
      })
    }
  </code></pre>
  <p>While executing I am getting the new token from the <code>getToken</code> method, but the retry of the same HTTP call is not happening.</p>
  <p>The execution of HTTP request stops after obtaining the refresh token from the <code>getToken</code> method.</p>
  <p>Can somebody please help on this issue</p>