Categories
JavaScript Answers

How to fix property ‘catch’ does not exist on type ‘Observable’ with Rxjs?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *