Skip to content

Instantly share code, notes, and snippets.

@paullessing
Last active February 25, 2018 17:46
Show Gist options
  • Save paullessing/028ca4bb52744a4f5929e0a9509dadff to your computer and use it in GitHub Desktop.
Save paullessing/028ca4bb52744a4f5929e0a9509dadff to your computer and use it in GitHub Desktop.
Handling Errors in NgRx Effects - Snippet 3 (TodoEffects, bad error handling)
@Injectable()
export class TodoEffects {
@Effect()
public fetchListOfTodos$: Observable<void> = this.action$.pipe(
ofType(ActionTypes.FETCH_TODO_LIST),
switchMap(() => this.todoListService.fetchTodoList()),
map((todos: Todo[]) => {
return {
type: ActionTypes.TODO_LIST_FETCHED,
payload: { todos }
};
}),
catchError((error) => {
return Observable.of({
type: ActionTypes.FETCH_TODO_LIST_FAILED,
payload: { error }
});
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment