简体   繁体   中英

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.

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. Is it possible to wait for certain time (5 seconds), just throw error manually and do not make any more requests?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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