Skip to content

Function: catchErrorSource()

catchErrorSource<Payload, TypePrefix>(typePrefix): (source$) => Observable<Payload | Action<any, `${TypePrefix}.error$`>>

Defined in: libs/rxjs/src/lib/sources/catch-error-source.operator.ts:24

catchErrorSource is a custom RxJS operator that converts an RxJS Observable of any values into a source of errors, using RxJS' catchError operator. It takes one argument, TypePrefix, and prefixes it to create an object of type Action<any, ${TypePrefix}.error$>.

Example: Catching errors from a source

typescript
import { timer, map } from 'rxjs';

const timer$ = timer(1000).pipe(
  map(n => ({ type: 'timer$', payload: n.fakeNumberMethod() })),
  catchErrorSource('timer'),
);

timer$.subscribe(console.log);
// { type: 'timer.error$', payload: 'Error: n.fakeNumberMethod is not a function' }

Type Parameters

Payload

Payload

TypePrefix

TypePrefix extends string

Parameters

typePrefix

TypePrefix

Returns

(source$): Observable<Payload | Action<any, `${TypePrefix}.error$`>>

Parameters

source$

Observable<Payload>

Returns

Observable<Payload | Action<any, `${TypePrefix}.error$`>>