What is the best way to deal with a fetch error in react redux?

前端 未结 6 1968
名媛妹妹
名媛妹妹 2020-12-04 04:41

I have one reducer for Clients, one other for AppToolbar and some others...

Now lets say that I created a fetch action to delete client, and if it fails I have code

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 05:34

    what I do is I centralize all error handling in the effect on a per effect basis

    /**
     * central error handling
     */
    @Effect({dispatch: false})
    httpErrors$: Observable = this.actions$
        .ofType(
            EHitCountsActions.HitCountsError
        ).map(payload => payload)
        .switchMap(error => {
            return of(confirm(`There was an error accessing the server: ${error}`));
        });
    

提交回复
热议问题