title: Use a promise in Angular HttpClient Interceptor
body: <p>Can I use promise within <code>HttpInterceptor</code>? For example:</p>
  
  <pre><code>export class AuthInterceptor implements HttpInterceptor{
  this.someService.someFunction()
      .then((data)=&gt;{
         //do something with data and then
         return next.handle(req);
      });
  }
  </code></pre>
  
  <p>why I need this? because I need to get a token to add to request header before making the request to the server.</p>
  
  <p>My interceptor:</p>
  
  <pre><code>@Injectable()
  export class AuthInterceptor implements HttpInterceptor{
  
      constructor(private authService: AuthService){}
  
      intercept(req: HttpRequest&lt;any&gt;, next: HttpHandler) : Observable&lt;HttpEvent&lt;any&gt;&gt;{
          console.log('Intercepted!');
          // return next.handle(req);
          this.authService.getToken()
              .then((token)=&gt;{
                  console.log(token);
                  const reqClone = req.clone({
                      headers: req.headers
                              .set('Authorization', 'Bearer ' + token)
                              .append('Content-Type', 'application/json')
                  });
                  console.log(reqClone);
                  return next.handle(reqClone);
              })
              .catch((err)=&gt;{
                  console.log('error in interceptor' + err);
                  return null;
              });
      }
  }
  </code></pre>
  
  <p>Request:</p>
  
  <pre><code>this.http.post(this.baseURL + 'hero', data)
                      .subscribe(
                              (res: any) =&gt; {
                                  console.log('Saved Successfully.');
                                  console.log(res);
                              },
                              (err: any) =&gt; {
                                  console.log('Save Error.' + err);
                              }
                          );
  </code></pre>
  
  <p>Problems I am facing:</p>
  
  <p>->I get this error before the promise is resolved.</p>
  
  <pre><code>You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
  </code></pre>
  
  <p>Promise resloves and I get my token but after the error.</p>