0

I have been using package rx in NodeJS and everything is ok. Now, I tried to use rxjs (newer version of rx), and I don't understand anything.

When my Observable fails, I want to transform it in another one. Tipically, I would do it with catch, but it doesn't work anymore.

//I know it will never fail but it's just for the example
Rx.of(4).catch(err => Rx.of(7));

But I get:

Rx.of(...).catch is not a function

Same with onErrorResumeNext

Rx.of(4).onErrorResumeNext(Rx.of(7));

Rx.of(...).onErrorResumeNext is not a function

What am I doing wrong?

1 Answer 1

1

catch is renamed with catchError from RxJs 6.0.

They introduced a new operator called pipe where you can add infinite number of chained operation including error catching.

import { catchError } from 'rxjs/operators';

Rx.of(4)
  .pipe(
    catchError(err => Rx.of(7))
   )

Reference : https://www.learnrxjs.io/operators/error_handling/catch.html

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. Understood. I had to use const { catchError } = require('rxjs/operators'); instead, because I'm using Node. I will accept in 6 minutes :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.