angular - 自定义错误处理程序未捕获 zone.js 中的异常
问题描述
我有一个自定义错误处理程序设置来捕获所有未捕获的异常:
@Injectable()
export class CustomErrorHandler implements ErrorHandler {
async handleError(err: any) {
console.log('error: ', err)
}
}
这似乎有效,除非 Firebase 离线。我在控制台中看到了这个:
index.esm.js:106 [2021-09-23T17:23:48.765Z] @firebase/firestore: Firestore (8.10.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: The operation could not be completed
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
zone-evergreen.js:659 Unhandled Promise rejection: Failed to get document because the client is offline. ; Zone: <root> ; Task: Promise.then ; Value: FirebaseError: Failed to get document because the client is offline.
zone-evergreen.js:364 Uncaught (in promise) FirebaseError: Failed to get document because the client is offline.
我故意阻止网络,以便找到一种方法来捕获此错误并通知客户端。我发现捕获这些错误的唯一方法是将 Firebase 调用包装在try/catch
.
这些错误为什么/如何使它超出我的范围CustomErrorHandler
?如何在不将每个 Firebase 调用包装成try/catch
块的情况下捕获它们?
解决方案
推荐阅读
- python - 在 Spark 中读取多个 CSV 文件并制作一个 DataFrame
- python-3.x - chrome://webrtc-internal stats 中使用的时区是什么?
- apache-kafka - 如何处理 Kafka 中的 i18n?
- java - 与 Java 通配符混淆
- mongodb - 如何在 NestJS Typescript 中访问 mongo 的 .pre() 钩子的 req 、 res 内部函数
- typo3 - 在 TYPO3 中包含外部表的可能方法
- google-apps-script - 如何根据 Google 表格中的单元格值防止表单提交的响应更新
- javascript - 我正在尝试制作一个使用通过 HTML 输入的值并返回一个函数的 javascript 函数
- reactjs - 向对象添加错误键时,TypeScript 未捕获错误
- c# - 如何在 TimeFrom 和 TimeTo 之间选择未分配的时间跨度