title: how to throw observable error in angular http interceptor
body: <p>I tried to throw an observable error in the interceptor and then handles this error. but I can't. When success is false, I can also receive successful subscribe.</p>
  
  <p>I tried to return a value again in <code>next.handle(restReq)</code>. But I failed and did not subscribe to anything</p>
  
  <h3>restApi return like this</h3>
  
  <pre class="lang-json prettyprint-override"><code>{
    "success": false,
    "data": {
      "name": "Bad Request",
      "message": "123",
      "code": 0,
      "status": 400,
      "type": "yii\\web\\BadRequestHttpException"
    }
  }
  </code></pre>
  
  <h3>auth.service.ts</h3>
  
  <pre class="lang-js prettyprint-override"><code>import { Injectable } from '@angular/core';
  import { HttpClient } from '@angular/common/http';
  import { Observable } from 'rxjs/internal/Observable';
  
  @Injectable({
    providedIn: 'root'
  })
  export class AuthService {
    private sessionUrl = '/wechat/session';
  
    constructor(
      private http: HttpClient
    ) { }
  
    getSession(): Observable&lt;any&gt; {
      return this.http.post&lt;any&gt;(this.sessionUrl, {});
    }
  }
  </code></pre>
  
  <h3>auth.component.ts</h3>
  
  <pre class="lang-js prettyprint-override"><code>import { Component, OnInit } from '@angular/core';
  import { AuthService } from '@core/services/auth.service';
  import { interval } from 'rxjs/internal/observable/interval';
  import { switchMap, take } from 'rxjs/operators';
  
  @Component({
   selector: 'app-auth',
   templateUrl: './auth.component.html',
   styleUrls: ['./auth.component.scss']
  })
  export class AuthComponent implements OnInit {
    constructor(
      private authService: AuthService
    ) { }
  
    ngOnInit(): void {
      this.authService.getLoginQrcode()
        .subscribe(
          data =&gt; console.log(data),
          error =&gt; console.log(error);
    }
  }
  </code></pre>
  
  <h3>http-interceptor.ts</h3>
  
  <pre class="lang-js prettyprint-override"><code>import { Injectable } from '@angular/core';
  import {
    HttpErrorResponse,
    HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse
  } from '@angular/common/http';
  
  import { Observable } from 'rxjs';
  
  @Injectable()
  export class RestInterceptor implements HttpInterceptor {
    intercept(req: HttpRequest&lt;any&gt;, next: HttpHandler): Observable&lt;HttpEvent&lt;any&gt;&gt; {
      let baseUrl = environment.baseUrl + '/' + environment.version;
      let headers = req.headers;
      const restReq = req.clone({
        headers,
        withCredentials: true
      });
  
      return next.handle(restReq);
    }
  }
  </code></pre>