Skip to content

Instantly share code, notes, and snippets.

@kosich
Last active May 5, 2019 10:02
Show Gist options
  • Save kosich/65d073b7f78173f5cc49118087187a35 to your computer and use it in GitHub Desktop.
Save kosich/65d073b7f78173f5cc49118087187a35 to your computer and use it in GitHub Desktop.
async error handler in RxJS
const { rxObserver } = require('api/v0.3');
const { timer, throwError } = require('rxjs');
const { mapTo, tap, catchError, switchMap } = require('rxjs/operators');
const error$ = timer(10).pipe(
switchMap(() => throwError('X'))
);
const omittedCatch$ = error$
.pipe(
catchError(err => {
testCall('omitted', err);
return timer(10).pipe(mapTo('o'));
})
);
const workingCatch$ = error$
.pipe(
catchError(err => testCall('catched', err))
);
error$.subscribe(rxObserver('Error'));
omittedCatch$.subscribe(rxObserver('Omitted'));
workingCatch$.subscribe(rxObserver('Working'));
function testCall(name, value){
return timer(10)
.pipe(
mapTo(value),
tap(rxObserver('> ' + name))
)
}
@jesilucu
Copy link

maksud dari const?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment