angular - 为什么在服务器关闭时无法在 Angular 中捕获 HTTP 错误?
问题描述
我的 Angular 9 中有一个 REST 服务来处理所有 HTTP 请求。当我关闭 REST 服务器时,出现错误console.log()
但我无法在服务中捕获它们:
return this.http.post<any[]>(this.path, data, header).pipe(
catchError((err: HttpErrorResponse) => {
console.log("---", err);
return of(null);
})
);
控制台输出始终是:
zone-evergreen.js:2845 HEAD https://SERVER/ net::ERR_CERT_COMMON_NAME_INVALID
为什么会发生这种情况,为什么会catchError
被忽视?
解决方案
对于与 http 调用相关的错误,您将在 catchError 中收到错误。在这种情况下,您的呼叫甚至没有到达任何服务器。为了捕获这些类型的错误,您可以通过实现 ErrorHandler 接口来设置全局错误处理程序。请参阅下面的链接以执行此操作:-
推荐阅读
- php - 将 UTF-16 转换为 UTF-8 后看到中文字母
- java - 如何通过输入向数组列表添加尽可能多的元素?
- c# - 在 C# 中使用时间跨度简化 if else 条件
- python - 如何编写一个python函数,当输入是一个列表时返回一个列表,当输入是一个非列表时返回一个非列表值?
- ios - 多方法混用时如何找到方法的原始实现
- python - RegEx :匹配除特定子字符串之外的所有行
- unity3d - 如何使用 Unity 获得纬度和经度值的准确性?
- firebase - 通过 Google Cloud API 区分云函数的 HTTP 和 onCall 触发器
- java - Spring Boot 关系返回 null
- c# - Visual Studio 2012 和 2015,添加 > 新项目 > 报告 > 水晶文件报告未找到