我的角11应用程序有一个恼人的问题:当我在本地机器上执行以下代码时,一切都很好,正确的错误消息将由我的toastrService显示。但是当它被部署到Azure时,我总是会发现出了问题!请再试一次!这是与HttpErrorResponse不同的错误情况下的错误消息(检查显示的错误消息的组件代码)。
我有以下拦截方法:
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).pipe(
catchError(err => {
// onError
console.log(err);
if (err instanceof HttpErrorResponse) {
console.log(err.status);
console.log(err.statusText);
if (err.status === 401) {
this.LogoutFromApplication();
}
}
return throwError(err);
}));
}以及以下组件逻辑:
this.httpService.post(url, body)
.subscribe((result) => {
...
},
(errorResponse) => {
this.operationFlag = false;
console.log(JSON.stringify(errorResponse));
if (errorResponse.error && errorResponse.error.ErrorMessage) {
this.toastr.showError(errorResponse.error.ErrorMessage);
} else {
this.toastr.showError("Something went wrong! Please try again!");
}
});不知何故,这个错误被拦截器吞没了。拦截器中的控制台日志显示错误存在,并且是一个HttpErrorResponse,但是在组件中记录了一个空对象,而errorResponse对象似乎是未定义的。
你能帮我找出问题所在吗?
发布于 2021-05-14 07:49:30
好的,事实证明,Adal5HttpService确实要对此负责。它似乎不正确地抛出错误,可能是在rxjs中更改这个部分之后的几年内。所以问题中的代码运行正常,这个问题和调查的信息是
不要把你的搜索范围缩小到问题最明显的地方,试着去看全局。
希望这对某人有帮助。
https://stackoverflow.com/questions/67521930
复制相似问题