title: Angular 2 Refresh access token on 401 error and repeat initial request
body: <p><strong>TLDR:</strong> My task is to complete 3 requests instead of 1 and return the last response as a response to the first request without any additional modifications of the request initiator.</p>
  
  <p>I have extended the Angular <code>Http</code> class to automatically append authorization headers to all of my requests and implement my own authorization error handling.</p>
  
  <p>It looks like this:</p>
  
  <pre><code>  request(url: string | Request, options?: RequestOptionsArgs): Observable&lt;Response&gt; {
  
      // ... append some headers
  
      super.request(url, options).catch((error: Response) =&gt; {
        if (error.status === 401 || error.status === 403 ) {
          // todo: Send refreshToken request to get new credentials
          // todo: Send current request again with new credentials
  
          // todo: If request is completed properly pretend everything was fine and return response
        }
      });
    }
  </code></pre>
  
  <p>I want to catch authorization errors, fix them by sending token refresh request and return proper response to the initial request.</p>
  
  <p>There's a lot of code using <code>http</code> now and I don't want to change it so the fixed response has to be returned as the initial would have been without anybody knowing about it.</p>
  
  <p>One of the approaches was to use synchronous requests but it's not a good idea I think.</p>
  
  <p>Could you tell please if the solution is possible and how can I achieve it?</p>
  
  <p>PS. There may be a problem when another request is executed while the token is being refreshed and crash into an authorization causing one more token refresh. But this is not that important now.</p>