onErrorResumeNext

When any of the provided Observable emits an complete or error notification, it immediately subscribes to the next one that was passed.

onErrorResumeNext<T, R>(...nextSources: Array<ObservableInput<any> | Array<ObservableInput<any>> | ((...values: Array<any>) => R)>): OperatorFunction<T, R>

Parameters

nextSources

Type: Array | Array> | ((...values: Array) => R)>.

Returns

OperatorFunction<T, R>: An Observable that emits values from source Observable, but - if it errors - subscribes to the next passed Observable and so on, until it completes or runs out of Observables.

Description

Execute series of Observables no matter what, even if it means swallowing errors.

onErrorResumeNext is an operator that accepts a series of Observables, provided either directly as arguments or as an array. If no single Observable is provided, returned Observable will simply behave the same as the source.

onErrorResumeNext returns an Observable that starts by subscribing and re-emitting values from the source Observable. When its stream of values ends - no matter if Observable completed or emitted an error - onErrorResumeNext will subscribe to the first Observable that was passed as an argument to the method. It will start re-emitting its values as well and - again - when that stream ends, onErrorResumeNext will proceed to subscribing yet another Observable in provided series, no matter if previous Observable completed or ended with an error. This will be happening until there is no more Observables left in the series, at which point returned Observable will complete - even if the last subscribed stream ended with an error.

onErrorResumeNext can be therefore thought of as version of concat operator, which is more permissive when it comes to the errors emitted by its input Observables. While concat subscribes to the next Observable in series only if previous one successfully completed, onErrorResumeNext subscribes even if it ended with an error.

Note that you do not get any access to errors emitted by the Observables. In particular do not expect these errors to appear in error callback passed to Observable. If you want to take specific actions based on what error was emitted by an Observable, you should try out catchError instead.

Example

Subscribe to the next Observable after map fails

import { of } from 'rxjs'; import { onErrorResumeNext, map } from 'rxjs/operators'; of(1, 2, 3, 0).pipe( map(x => { if (x === 0) { throw Error(); } return 10 / x; }), onErrorResumeNext(of(1, 2, 3)), ) .subscribe( val => console.log(val), err => console.log(err), // Will never be called. () => console.log('that\'s it!') ); // Logs: // 10 // 5 // 3.3333333333333335 // 1 // 2 // 3 // "that's it!"

Overloads

onErrorResumeNext(v: ObservableInput<R>): OperatorFunction<T, R>

Parameters

v

Type: ObservableInput.

Returns

OperatorFunction<T, R>

onErrorResumeNext(v2: ObservableInput<T2>, v3: ObservableInput<T3>): OperatorFunction<T, R>

Parameters

v2

Type: ObservableInput.

v3

Type: ObservableInput.

Returns

OperatorFunction<T, R>

onErrorResumeNext(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>): OperatorFunction<T, R>

Parameters

v2

Type: ObservableInput.

v3

Type: ObservableInput.

v4

Type: ObservableInput.

Returns

OperatorFunction<T, R>

onErrorResumeNext(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>): OperatorFunction<T, R>

Parameters

v2

Type: ObservableInput.

v3

Type: ObservableInput.

v4

Type: ObservableInput.

v5

Type: ObservableInput.

Returns

OperatorFunction<T, R>

onErrorResumeNext(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>): OperatorFunction<T, R>

Parameters

v2

Type: ObservableInput.

v3

Type: ObservableInput.

v4

Type: ObservableInput.

v5

Type: ObservableInput.

v6

Type: ObservableInput.

Returns

OperatorFunction<T, R>

onErrorResumeNext(...observables: Array<ObservableInput<any> | ((...values: Array<any>) => R)>): OperatorFunction<T, R>

Parameters

observables

Type: Array | ((...values: Array) => R)>.

Returns

OperatorFunction<T, R>

onErrorResumeNext(array: ObservableInput<any>[]): OperatorFunction<T, R>

Parameters

array

Type: ObservableInput[].

Returns

OperatorFunction<T, R>

See Also