Last active
October 3, 2017 06:30
-
-
Save tuanngominh/80ac867abbe34d6565bcf2fbde7ccb36 to your computer and use it in GitHub Desktop.
Return observable from catch operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rxjs 5.4, ngrx 4.0.0, angular 4.0.0 | |
import {Injectable} from '@angular/core'; | |
@Injectable() | |
export class Task1Effects { | |
@Effect() task1$: Observable<Action> = this.actions$ | |
.ofType('TASK1') | |
.switchMap((action: Action1) => | |
this.service1.doSomething(action.param1) | |
.map((result) => new Action1Success(result)) | |
// https://www.learnrxjs.io/operators/error_handling/catch.html | |
// Remember to return an observable from the catch function! | |
.catch((e: Error) => Observable.of(new Action1Error(e.message))) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment