首页 > 解决方案 > 在 NgRX Effect 中处理时,效果将不再起作用

问题描述

对于我的生活,我无法弄清楚为什么一旦抛出并拦截错误,效果将不再起作用

  @Effect()
  register$ = createEffect(() => {
    return this.actions$.pipe(
      ofType(RegisterAction),
      map(action => action.registrationInfo),
      mergeMap(registrationInfo => {
        return this.authService.createUser(registrationInfo.email, registrationInfo.password,
          registrationInfo.lastname, registrationInfo.firstname);
      }),
      map(credentialInfo => ProfileInitAction({credentialInfo})),
      catchError(error => [ProfileInitErrorAction(error)]),
    );
  });

标签: ngrxngrx-effects

解决方案


在 catchError 中添加 catch$ 似乎可以解决这个问题。

  register$ = createEffect(() => {
    return this.actions$.pipe(
      ofType(RegisterAction),
      map(action => action.registrationInfo),
      mergeMap(registrationInfo => {
        return this.authService.createUser(registrationInfo.email, registrationInfo.password,
          registrationInfo.lastname, registrationInfo.firstname);
      }),
      map(credentialInfo => ProfileInitAction({credentialInfo})),
      catchError((err, caught$) => {
        notify(this.translate.instant('pages.auth.register.notify.error' + ': ' + err['message']), 'error');
        return caught$;
      }),
    );
  });

推荐阅读