Skip to content

Instantly share code, notes, and snippets.

@tuanngominh
Last active October 3, 2017 06:30
Show Gist options
  • Save tuanngominh/80ac867abbe34d6565bcf2fbde7ccb36 to your computer and use it in GitHub Desktop.
Save tuanngominh/80ac867abbe34d6565bcf2fbde7ccb36 to your computer and use it in GitHub Desktop.
Return observable from catch operator
// 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