title: Angular 4 http interceptor refresh_token triggered too many times
body: <p>I am trying to decorate the built-in <code>request</code> method in angular Http.
  I am triggering a multitude of chained and/or asynchronous requests at the same time which in turn results in that the 401 response is triggered a lot of times simultaneously. This crashes the authorization as the same refresh token is used multiple times.</p>
  
  <p>So far, I've come this far:</p>
  
  <pre><code>request(url: string | Request, options?: RequestOptionsArgs): Observable&lt;Response&gt; {
      return super.request(url, options).catch(error=&gt; {
          if (error.status === 401) {
              return Observable.create((observer: Observer&lt;Response&gt;) =&gt; {
                  // Use promise to avoid OPTIONS request
                  this.oauthService.refreshToken().then((tokenResponse: Response) =&gt; {
                      console.debug('promise resolved');
  
                      observer.next(tokenResponse);
                      observer.complete();
                  });
              }).mergeMap((tokenResponse) =&gt; {
                  options = this.updateAuthHeader(options);
                  return super.request(url, options);
              });
          } else {
              return Observable.throw(error);
          }
      });
  }
  </code></pre>
  
  <p>My issue seems to be that i need to que the pending requests when a 401 has been encountered, or that i just lack the knowledge of how to achieve that with observables. As far as i understand the <code>mergeMap</code> should to this for me, but sadly they all trigger the request before my token has been refreshed.</p>
  
  <p>Any ideas of how to achieve this?</p>