Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import ErrorObservable or _throw in rxjs6? throw in rxjs

I am migrating to rxjs 6.0.0-ucandoit-rc.6. In version 5.5.2 I was using ErrorObservable to create errorous observable.

I was using the way recommended here: https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md

Because throw is a key word you could use _throw after import { _throw } from 'rxjs/observable/throw'.

However this is not recommended way to import in rxjs6 anymore.

What is correct way how to import _throw or ErrorObservable?

like image 749
Martin Nuc Avatar asked Apr 13 '18 21:04

Martin Nuc


People also ask

How do you return an observable error?

In order to retry the failed observable immediately after the error occurs, all we have to do is return the Errors Observable without any further changes. res => console. log('HTTP response', res), err => console.

What is pipe operator in RxJS?

A Pipeable Operator is a function that takes an Observable as its input and returns another Observable. It is a pure operation: the previous Observable stays unmodified. A Pipeable Operator is essentially a pure function which takes one Observable as input and generates another Observable as output.


1 Answers

In RxJS version 6, _throw has been renamed to throwError and should be imported like this:

import { throwError } from "rxjs";

Alternatively, you can install rxjs-compat alongside rxjs version 6 to continue to use the old, version 5 exports:

import { _throw } from "rxjs/observable/throw";

For more information, see the migration guide.

like image 137
cartant Avatar answered Sep 19 '22 18:09

cartant