我创建了一个注册用户的效果,但是当我尝试向现有用户注册时,它会调度成功动作。
显然,我想根据我在后端success: false or success: true
的条件发送失败动作。另外,我能通过效果两次调度失败动作吗?
效果如下:
@Effect() register$: Observable<Action> = this.actions$
.ofType(fromActions.REGISTER)
.pipe(
map((action: fromActions.Register) => action.payload),
switchMap(user => {
return this.authService.RegisterUser(user)
}))
.pipe(
map(message => ({ type: fromActions.REGISTER_SUCCESS, payload: message })),
catchError(err => {
return Observable.of({ type: fromActions.REGISTER_FAILURE, payload: err })
}));