正确处理ngrx效果 catchError。

问题描述 投票:1回答:1

你好,我有一个Effect,想正确处理错误。我想调用一个附加的动作与我的服务器端错误的内容。我怎么能做到这一点?

@Injectable()
export class AuthEffects {
    @Effect()
    registerUser$ = this.actions$.pipe(
      ofType(AuthActions.Action.CREATE_USER),
      switchMap(({user}) =>
        this.customersService.createNewUser(user).pipe(
          switchMap(() => [
            new ModalActions.SetModalType(null)
            ]
          ),
            catchError((err) => {
              if (foo) {
              new ModalActions.SetModalErrors(err.error); // <---- make an Action here
              } else {
              }
              return throwError(err);
            })

            )
        )
    );
angular ngrx
1个回答
1
投票

不幸的是,没有人回答,但无论如何,这工作。

catchError((err) => {
  if (err.error.email) {
    return of(new ModalActions.SetModalErrors(err.error));
  } else {
  this.notificationService.notify(Object.values(err.error)[0] as string);
  return throwError(err);
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.