由于Spring引导服务关闭,角度超时



我的angular前端发出了POST http请求。但后端Spring Boot服务已关闭(未启动(,因此我可以在几秒钟后看到Chrome控制台上出现以下错误:

岗位https://localhost:8080/report/datanet::ERR_TIMED_OUT

已经添加了错误回调来停止旋转,但这种情况似乎无法控制,所以它一直在旋转。这是我的代码:

this.dataService.getData(detailParam).subscribe(
(responseData: any) => {
this.closeLoading();
console.log(success);
},
(error) => {
this.closeLoading();
console.log(error);
}
);

如何捕捉net::ERR_TIMED_OUT错误并停止加载?

您可以使用rxjs运算符finalize来防止类似以下的重复代码:

dataService.getData(`detailParam`).pipe(finalize(() => closeLoading())).subscribe(
(responseData: any) => {
console.log('success');
},
);

它也更好,因为不推荐将多个函数传递给subscribe函数:

@已弃用--与其传递单独的回调参数,不如使用observer参数。采用单独回调参数的签名将在v8中删除。

但是,如果this.dataService.getData(detailParam)确实发出错误,那么您的代码应该可以工作。也许您可以提供此代码来查找此实现中的问题。

最新更新