Skip to content

Instantly share code, notes, and snippets.



Last active Feb 14, 2019
What would you like to do?
RxJS error management exploration
// index.ts as typed in
import { of, throwError } from 'rxjs';
import { map, switchMap, catchError, tap, finalize } from 'rxjs/operators';
const source = of('World').pipe(
map(x => { return { good: `Hello ${x}!` }; }),
// Comment out for testing regular behavior
switchMap((x) => throwError('bad')),
// Comment out to get subscribe's error handling
catchError((e) => {
// Doesn't break the stream (tap is called), return the given value to onNext, also call onCompleted.
return [{ error: e }];
// Calls onCompleted, no onNext call.
//return [];
// Rethrow an error, calls onError.
//return throwError('Not recoverable');
tap(() => {'Just tapping a bit');
finalize(() => {'Final step, always done');
x => console.log('Result:', x),
e => console.error('Error:', e),
() =>'Complete'),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.