在服务器做出错误响应后,我的应用程序不会发送任何进一步的请求。
我正在发送一个请求:
getMachineRules(rules: Array<string>): Observable<RulesResults> {
return this.http.post<RulesResults>('/rules', { nodes: rules })
.pipe(
catchError(this.handleError)
);
}
我的错误处理程序:
handleError(error) {
if (error.error instanceof ErrorEvent) {
console.error('An error occurred:', error.error.message);
} else {
console.error(
`Backend returned code ${error.status}, ` +
`body was: ${JSON.stringify(error.error)}`);
}
return throwError('Something bad happened; please try again later.');
}
我的管道如下所示:
ngAfterViewInit() {
this.rulesChanged
.pipe(
startWith({}),
switchMap(() => {
this.isLoadingResults = true;
return this.settings.getMachineRules(this.currentRules);
}),
map(data => {
this.isLoadingResults = false;
this.resultsLength = data.inputs?.length || 0;
return data;
}),
catchError(e => {
console.log("Error caught");
this.isLoadingResults = false;
this.resultsLength = 0;
return observableOf({ inputs: [] } as RulesResults);
})
).subscribe(
data => { return this.updateRules(data); },
);
}
我可以在控制台中看到“错误捕获”消息,updateRules()
即使在错误情况下,该方法似乎也能正常工作。
但是,在 404-Error-Response 之后,ngAfterViewInit()
不再调用该方法。UI 钢对交互做出反应。