简体   繁体   English

如何在AngularFire Observable中引发错误

[英]How to Throw error in AngularFire Observable

I am using following to code read an object from firebase database using angularfire in my ionic app, but i want to let it wait for certain time if.. no data recieved or unable to connect, i want to throw error. 我正在使用以下代码在我的离子应用程序中使用angularfire从firebase数据库中读取对象,但是如果..没有数据接收或无法连接,我想让它等待一定的时间,我想抛出错误。

return this.db.object('/cmtoci')
      .valueChanges()

I can see the error in google chrome console, but it appears around 15-20 seconds in case of no internet connection and resume the request when internet connection is back. 我可以在Google Chrome浏览器控制台中看到该错误,但如果没有互联网连接,它将在15到20秒左右出现,并在互联网连接恢复时恢复请求。 Is it possible to wait for certain time (5 seconds), just throw error manually and do not make any more requests? 是否可以等待特定时间(5秒),只是手动抛出错误并且不再发出任何请求?

GET https://xxx.firebaseio.com/.lp?start=t&ser=221147393&cb=5&v=6 net::ERR_NAME_NOT_RESOLVED

I think this what are you looking for: 我认为这是您在寻找什么:

 this.db.database.object('/cmtoci').subscribe(
      obj => {
        // logic
      },
      error => {
        // handle/report the error
      }
    );

Let me know if this method is good for you. 让我知道此方法是否对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM