title: Angular6 HttpClient catchError not working
body: <p>CatchError is completelly ignored in 401 response.</p>
  
  <p>I have httpInterceptor that handles oauth2 authentication.</p>
  
  <p>Relevant code is : </p>
  
  <pre><code>import { filter, take, switchMap, map, catchError } from 'rxjs/operators';
  //ommited
  if (authService.hasRefreshToken()) {
      return authService.doRefreshToken().pipe(switchMap(tokenResponse =&gt; {
              const accessToken = tokenResponse['access_token'];
              this.tokenSubject.next(accessToken);
              return &lt;Observable&lt;HttpEvent&lt;any&gt;&gt;&gt; next.handle(this.addToken(req, accessToken));
          }), catchError((err: any, caught: any) =&gt; {
              console.log(err)
              return Observable.throw(err);
          })
      )
  }
  </code></pre>
  
  <p>AuthService class:</p>
  
  <pre><code>export class AuthService {
      doRefreshToken() {
          //ommited
          return this.httpClient.post(environment.baseUrl + this.tokenEndpoint, null, requestOptions).pipe(
              map(tokenResponse =&gt; {
                  this.saveToken(tokenResponse);
                  return tokenResponse;
              }),
              catchError((err: any, caught: Observable&lt;Object&gt;) =&gt; {
                  //refreshing token failed (refrech token invalid or expired) redirect to login and wipe everything
                  this.logout();
                  return Observable.throw(err);
              }));
      }
  }
  </code></pre>
  
  <p>Everything works fine for 200 response, but 401 error is completely ignored.
  Am i using this new catchError the wrong way ?</p>
  
  <p>P.S. this piece of code was working just fine with plain old catch , but now when i migrated to angular6 pipe and catchError same stuff just doesnt work.</p>
  
  <p>EDIT : </p>
  
  <p>Breakpoint on catchError reveals </p>
  
  <blockquote>
    <p>"SyntaxError: Unexpected end of input
        at AuthService.push../src/app/common/auth/auth.service.ts.AuthService.doRefreshToken</p>
  </blockquote>
  
  <p>Actual response from the server is :</p>
  
  <pre><code>{
   "error" : "invalid_token",
   "error_description" : "Refresh token expired"
  }
  </code></pre>
  
  <p>Headers :</p>
  
  <pre><code> Request Method: POST
   Status Code: 401 
  </code></pre>