检查推送是否成功 - angularfire2

Check if push is successful - angularfire2

目前我正在开发一个与 Firebase 数据库通信的 Ionic2 应用程序。在更新节点时,它有时会起作用,有时却不起作用。 所以我厌倦了使用以下代码处理错误:

this.db.list("/Events/" + this.eventID+ "/teilnehmer").push(this.userID)
        .then(resolve => {
          console.log('success');
        }, reject => {
          console.log('error');
        })
        .catch(reject => {
          console.log('catch');
        });

但即使我断开互联网连接也不会抛出任何错误。 如果推送不成功,有人知道我该如何处理错误吗?

我遇到过推送不 return 承诺的相同情况,所以我在 github FirebaseListObservable push() takes too long to add 上提出了问题,但不幸的是它没有解决,我通过电子邮件联系了 firebase 支持,支持团队审查了我的问题并检查了我发送的代码,并回复说代码中没有任何事情可以做,并建议我清除phone的存储缓存,我也这样做了,问题得到解决,

这是来自 firebase 支持的邮件

Hi xxxx,

I suggest that you try clearing your phone's cache before proceeding again, its memory might be too high. To do this, go to: Settings -> Storage -> Cached Data. Select it then then choose ok (for clearing the cache). Also please check this the same issue raised on Github and answered by one of our engineers.

If the issue persists after trying the proposed suggestions, please get back to me with a minimal and runnable code that we can use to simulate this, possibly a plunkr or jsfiddle code, or a from the scratch code that can demonstrate the issue.

Regards, xxxx

如果您想处理这个问题,您可以考虑设置超时,因为如果 Firebase 没有 return 任何东西并解决,Promise 将只停留在 'pending' 中,拒绝/捕获永远不会触发。

例如,您可以使用 Promise.race() 执行此操作:Example Promise timeout with Promise.race() also check this thread: