问题:
我有一个非常简单的 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/