javascript - firebase.database 设置不会捕获网络故障时的错误

标签 javascript firebase asynchronous firebase-realtime-database network-programming

问题:
我有一个非常简单的 firebase 问题。我的 .catch 函数从未被触发。

背景:
如果网络已连接,我就能够成功保存到 firebase 并调用我的 .then 函数。但是,如果我断开与互联网的连接,则永远不会调用 .catch 。我在 Chrome 开发工具中看到网络故障。他们只是尝试连接但从未连接(互联网已断开)。

firebase.database()
    .ref('password')
    .set("hat")
    .then(() => {
      debugger;
    })
    .catch((error) => {
      debugger;
    })

最佳答案

答案:
网络连接丢失并不是 Firebase 的故障状态。

背景:
根据他们的Offline-Capabilities docs

Firebase applications work even if your app loses its network connection temporarily.

我能够验证我的 .catch 语句是否可以处理其他类型的故障,例如不正确的权限。

解决方法:
我当前的计划是手动实现超时,如果网络请求挂起时间过长,该超时就会触发。

关于javascript - firebase.database 设置不会捕获网络故障时的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48408260/

相关文章:

javascript - 如何检查 Angular 是否已经有模块?

javascript - 我在 Wordpress 中加载更多帖子 Ajax 按钮不起作用

android - 仅允许我的应用程序的用户将值从 false 更改为 true 的最安全的安全规则是什么?

c# - 异步操作不会在await命令处停止

javascript - AngularJS + CSS3 TransformAnimation 向左滑动时我们会丢失内容吗?无法向后滚动?

javascript - 查找数组中元素的最大数量

Scala 向自己发送消息好还是坏?

javascript - 获取从 angularJS 中的异步 $http 服务获取的对象,以便在 $scope 中全局访问

火警警告 : Invalid query string segment - Warning when deploying simple Firebase Cloud function

ios - 使用 Firebase/Google Cloud Functions 推送通知