0

I tried to implement catch handling in a service, but i've got an undefined function error in my console.

This is the error message:

TypeError: rxjs_internal_Observable__WEBPACK_IMPORTED_MODULE_2__.Observable.throw is not a function

import { Injectable } from '@angular/core';
import { config } from '../../../config/config';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { catchError } from 'rxjs/operators';
import { HttpResponseHandler } from './http-response-handler.service';
import { Observable } from 'rxjs/internal/Observable';

@Injectable()
export class DataService<T> {

constructor(
        protected url: string,
        protected httpClient: HttpClient,
        protected responseHandler: HttpResponseHandler
    ) { }

    getOneById<T>(id): Observable<T> {
        return this.httpClient
            .get<T>(config.ecmBackUrl + this.url + '/' + id)
            .pipe(catchError((err, source) => this.responseHandler.onCatch(err, source)));
    }
}

@Injectable()
export class HttpResponseHandler {

    public onCatch(response: any, source: Observable<any>): Observable<any> {
       console.log(response);
    }
}
Aymen Kanzari
  • 1,765
  • 7
  • 41
  • 73
  • 1
    Possible duplicate of ["rxjs" observable.throw is not a function - Angular4](https://stackoverflow.com/questions/45464852/rxjs-observable-throw-is-not-a-function-angular4) – j4rey Mar 05 '19 at 10:33

1 Answers1

1

change the import path of the Observable

from

import { Observable } from 'rxjs/internal/Observable';

to

import { Observable } from 'rxjs/Observable';
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80