Sometimes, we want to fix property ‘catch’ does not exist on type ‘Observable’ with Rxjs.
In this article, we’ll look at how to fix property ‘catch’ does not exist on type ‘Observable’ with Rxjs.
How to fix property ‘catch’ does not exist on type ‘Observable’ with Rxjs?
To fix property ‘catch’ does not exist on type ‘Observable’ with Rxjs, we can use the catchError function.
For instance, we write
import { Observable } from "rxjs";
import { catchError } from "rxjs/operators";
//...
this.http.request(method, url, options).pipe(
catchError((err: HttpErrorResponse) => {
//...
})
);
to call request with pipe to pipe the request results.
Then we call catchError in pipe to catch any errors are returned by the observable returned by request.
Conclusion
To fix property ‘catch’ does not exist on type ‘Observable’ with Rxjs, we can use the catchError function.