我现在看到很多网络问题。在 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 是为了在正常情况下暂时离线使用而构建的。
关于javascript - 我可以在 JavaScript 中捕获此 Firestore 消息吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61592196/