Created
February 25, 2018 17:44
-
-
Save paullessing/eeffe3d91095dc13c39d92911b1ed6bd to your computer and use it in GitHub Desktop.
Handling Errors in NgRx Effects - Snippet 4 (TodoEffects)
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
@Injectable() | |
export class TodoEffects { | |
@Effect() | |
public fetchListOfTodos$: Observable<void> = this.action$.pipe( | |
ofType(ActionTypes.FETCH_TODO_LIST), | |
switchMap(() => | |
this.todoListService.fetchTodoList().pipe( | |
map((todos: Todo[]) => { | |
return { | |
type: ActionTypes.TODO_LIST_FETCHED, | |
payload: { todos } | |
}; | |
}), | |
// handle failure in todoListService.fetchTodoList() | |
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