当遇到onTrySignin
错误响应时,我遇到以下方法(HTTP
)的问题。 catch
电话后HTTP
阻止Side Effect
阻止Action
出现console.log
错误。如果我Observable
我收到此错误。
TypeError:您提供了' undefined'预期流的地方。您可以提供Observable,Promise,Array或Iterable。
如何保留mergeMap
流并将响应传递到下一个块(Actions
),在这种情况下我可以触发其他FailedSignin()
,(onTrySignin = this.actions$
.ofType(AuthActions.TRY_SIGNIN)
.map((action: AuthActions.TrySignin) => {
return action.payload;
})
.switchMap((action: DispatchAction) => {
const trySignInPayload: TrySignInPayload = action.payload;
return this.httpService.postRequest('Account/Login', (trySignInPayload.loginData))
.catch((error: any) => {
console.log(error)
return Observable.empty();
})
.mergeMap((response: HttpResponse<any>) => {
switch (response.status) {
case 200:
if (trySignInPayload.returnUrl) {
this.router.navigate([trySignInPayload.returnUrl]);
} else {
this.router.navigate(['/dbapp']);
}
return Observable.concat(
Observable.of(new AuthActions.GenerateAntiforgeryToken()),
Observable.of(new AuthActions.Signin(fromAuth.authId, this.fetchUserData()))
);
case 401:
case 404:
return Observable.concat(
Observable.of(new AuthActions.FailedSignin()),
Observable.empty()
);
default:
return Observable.concat(
Observable.of(new AuthActions.FailedSignin()),
Observable.empty()
);
}
})
}).catch((error) => {
return Observable.throw(error);
});
) ?
httpService
这是我的public postRequest(apiUrl: string, jsonData: {} = {}): Observable<any> {
return this.httpService.post(this.baseUrl + apiUrl, JSON.stringify(jsonData),
{observe: 'response', reportProgress: true, withCredentials: true});
}
filter_vars <- c("source", "medium", "campaign", "userType", "deviceCategory", "Condition",
"Voice", "Format", "Type", "Stage_Topic"),
答案 0 :(得分:1)
You need to create a disposable stream, this is how we do it:
@Effect()
login$: Observable<Action> = this.actions$
.ofType(authActions.LOGIN)
.switchMap((action: any) => {
// @Effect stream is completing when the error occurs, preventing any further
// actions. Therefore create a disposable stream to keep @Effect stream alive
return Observable.of(action)
.switchMap((action: any) => {
return this.apiService.login(action.payload);
})
.map((x: any) => {
return new authActions.SetTokensAction({ token: x.data.token });
})
.catch((error: any) => {
return Observable.of(new authActions.LoginFailedAction(error));
});
});