How to throw control an Exception in a Subscription that uses a promise

#1

Hi guys, I have the following code in a small test:

constructor(public navCtrl: NavController, public http: HTTP, public http2: HttpClient) {

  this.a().subscribe(() => {

    }, () => console.log("error"))
  }

  a(): Observable<any> {
    return new Observable(observer => {
      this.http.get("d", {}, {}).then(() => {
        observer.next(1);
        observer.complete();
      })
    })
  }

How can I get the , () => console.log("error") in the subscription be executed when an exception occurs in the promise?.

Thanks.

#2

Ok I totally forgot about map and could do it like this:

constructor(public navCtrl: NavController, public http: HTTP, public http2: HttpClient) {

 this.a().subscribe(data => {
      console.log(data)
    }, () => console.log("error"))
  }

  a(): Observable<any> {
    return fromPromise(this.http.get("htaatps://ionicframework.com", {}, {}))
    .pipe(
      map(data => {return data.data})
    ) 
  }

That gives me only the data as I want or throws an error if something goes wrong.