javascript - 我可以在 JavaScript 中捕获此 Firestore 消息吗?

标签 javascript firebase error-handling google-cloud-firestore

我现在看到很多网络问题。在 JavaScript 控制台中,我看到以下消息:

@firebase/firestore: Firestore (7.14.2): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds. 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.

我可以以某种方式捕获它并将其显示给用户吗?

<小时/>

编辑: 一个澄清。当网络浏览器离线时,此消息不是问题。在这种情况下,一切都会按我的预期进行。我的代码中有这个:

await firebase.firestore().enablePersistence({ synchronizeTabs: true })

但是,当 navigator.onLine === true 但无法访问 Firestore 时,我首先看到上面的控制台消息。之后我收到一个错误:

Uncaught (in promise) FirebaseError: Failed to get document because the client is offline.

此消息有误。浏览器未离线。 Firebase 处于“离线”状态(从浏览器的 Angular 来看)。

我当然可以解码该消息并向用户提供正确的信息,但我宁愿有一个官方的方法来处理这个问题。

最佳答案

这不是一个错误,这是一个通知。是抓不到的。它告诉您 Firestore SDK 发现很难访问 Firestore 服务,并且只会使用缓存,直到该问题解决为止。离线不是错误情况,因为 Firestore SDK 是为了在正常情况下暂时离线使用而构建的。

您可能想要read more about how the Firestore cache works .

关于javascript - 我可以在 JavaScript 中捕获此 Firestore 消息吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61592196/

相关文章:

允许管理员用户读取/写入所有其他用户的 firebase 安全规则是否会造成安全漏洞?

ios - 几周后 Firebase 推送通知不起作用

javascript - process.on 回调中引用错误

javascript - jQuery - 检查 .json 文件是否有效

javascript - React styled-components theme-provider 动态主题

javascript - moduleDirectories 键无法导入我的测试实用程序

firebase - google_sign_in 包中的 getServerAuthToken 返回 null

symfony - 通过覆盖ExceptionController的Symfony自定义错误页面

error-handling - 如何使用catch将屏幕上的错误捕获到TCL中的变量中

javascript - jQuery 和事件处理程序,为什么我拆分选择器很重要?