title: Return a Observable from a Subscription with RxJS
body: <p>I currently have a service that do a HTTP request to an API to fetch data. There are some logic that I want to do to the observable from within the service, but I still want to also subscribe to the Observable in my Component so that I can return any errors to the Component and to the user.</p>
  
  <p>Currently I do:</p>
  
  
  
  <pre><code>// service.ts
  getData(): Observable&lt;any&gt; {
      return this.http.get(url).pipe(catchError(this.handleError)
  }
  
  // component.ts
  ngOnInit() {
      this.service.getData().subscribe(res =&gt; {
          // Do my logic that belong to the service.ts
          // ...
  
          // Do my logic that belongs in the component.ts
          // ...
      }, err =&gt; this.errors = err)
  }
  </code></pre>
  
  <p>What I would like to do is to refactor this so that I handle the logic related to the subscription and the service.ts within the getData() method, and then return an Observable with the HTTP response and any errors to the Component so that I can continue doing things there.</p>
  
  <p>What's the pattern to do this?</p>