【问题标题】:NgRx effect does not trigger fail conditionNgRx 效果不会触发失败条件
【发布时间】:2021-04-10 21:28:49
【问题描述】:

我试图用我的效果模拟一个失败案例,但由于某种原因,它没有捕获错误并触发AuthActions.signInError

facebookSignIn$ = createEffect(() =>
  this.actions$.pipe(
    ofType(AuthActions.facebookSignIn),
    switchMap(() =>
      from(this.authService.facebookSignIn()).pipe(
        map(() => AuthActions.signInSuccess()),
        catchError((err) =>
          of(
            AuthActions.signInError({
              errorMessage: err.message,
              errorCode: err.code,
            })
          )
        )
      )
    )
  )
);

这里是服务:

facebookSignIn(course: ICourse = null): Promise<void> {
  const provider = new firebase.auth.FacebookAuthProvider();
  return this.afAuth
    .signInWithPopup(provider)
    .then(async (result) => {
      if (result) {
        const doc = await this.firebaseService.docExists(`/users/${result.user.uid}/`);
        if (!doc) {
          const user: IUser = {
            uid: result.user.uid,
            email: result.user.email,
            displayName: result.user.displayName,
            photoURL: result.user.photoURL,
          };
          await this.userService.processNewUser(
            user,
            result.additionalUserInfo.profile['first_name'],
            result.additionalUserInfo.profile['last_name']
          );
        }
        if (course) {
          this.builderSignIn(course, result.user.uid);
        }
      }
    })
    .catch((error) => {
      this.toastrService.warning('Something has gone wrong. Please try again.', 'Oops!');
      this.logger.debug('An error occurred during Facebook Sign In');
      this.logger.error(error.message);
    });
}

这是通话记录:

【问题讨论】:

    标签: javascript angular firebase ngrx


    【解决方案1】:

    在 promise catch 中,您可能需要重新抛出错误才能在可观察流中捕获它:

    .then(....)
    .catch((error) => {
      ....
      this.logger.error(error.message);
      throw error; // or throw new Error(error.message)
    });
    

    【讨论】:

      猜你喜欢
      • 2019-07-02
      • 1970-01-01
      • 2019-07-02
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 2014-10-07
      • 1970-01-01
      相关资源
      最近更新 更多