On the Angular 2 documentation page for using the Http service, there is an example.
getHeroes (): Observable {
return this.http.get(this.ur
In angular 8:
for catch:
import { catchError } from 'rxjs/operators';
for throw:
import { Observable, throwError } from 'rxjs';
and code should be written like this.
getEmployees(): Observable {
return this.http.get(this.url).pipe(catchError(this.erroHandler));
}
erroHandler(error: HttpErrorResponse) {
return throwError(error.message || 'server Error');
}