你好,我有一个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);
})
)
)
);
不幸的是,没有人回答,但无论如何,这工作。
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);
}
}