使用redux和Angular,我有以下效果:
@Effect()
public authenticate: Observable<Action> = this.actions
.ofType(AUTHENTICATE)
.pipe(
map((action: AuthenticateAction) => action.payload),
switchMap(payload => {
return this.userService.authenticateUser(payload.email, payload.password).pipe(
map(auth => new AuthenticationSuccessAction({ auth: auth })),
catchError(error => of(new HttpErrorAction({ error: error })))
);
})
);
服务:
public authenticateUser(email: string, password: string): Observable<IAuthentication> {
const formData: FormData = new FormData();
formData.append('email', email);
formData.append('password', password);
return this.httpClient.post('/api/auths/useraccounts', formData) as Observable<IAuthentication>;
}
当POST失败时,永远不会调度HttpErrorAction。
答案 0 :(得分:0)
原来我忘了我有一个HttpInterceptor,我抓住了这样的http错误:
return next.handle(authReq).pipe(catchError(
(error) => {
return of(error);
}
如果我想把错误搞砸到效果,我会做类似的事情:
return Observable.throw(error);