Appearance
Flow Diagram
Appearance
Catches errors from the source Observable and handles them by returning a new Observable or re-throwing — keeps the stream alive after an error.
catchError<T, O extends ObservableInput<any>>(selector: (err: any, caught: Observable<T>) => O): OperatorFunction<T, T | ObservedValueOf<O>>source: --1--2--X
catchError(() => of(0))
result: --1--2--0|
(error replaced with fallback value)
import { of } from 'rxjs'
import { catchError, retry } from 'rxjs/operators'
import { ajax } from 'rxjs/ajax'
ajax.getJSON('/api/data').pipe(
retry(2),
catchError(err => {
console.error('Failed after 2 retries', err)
return of({ data: [], error: true })
})
).subscribe(response => render(response))