0

I am using Angularfire2 along with Ionic2 and looking for a way to catch errors on FirebaseListObservable subscribe() function.

I am subscribing to fbData which is a FirebaseListObservable, and when I switch my browser/device offline, the (error) function is never called. I don't understand why.

My objective is to get data from the localStorage if the user is offline or firebase is not reachable.

Here is my simplified code:

export class MyService { fbData: FirebaseListObservable<any[]>; constructor(private af: AngularFire) { this.data = af.database.list('/data', { preserveSnapshot: true }); } updateData() { return new Promise<any[]>((resolve, reject) => { this.fbData.subscribe( (snapshots) => { resolve(snapshot.val()); }, (error) => console.log('error: ', error) // NEVER CALLED ); }); } 

1 Answer 1

2

Firebase will not throw an error if the network is unreachable. The SDK silently waits for the socket connection to build up. The subscription can only error out if the security rules denies read access to the query.

If you want to implement such a timeout scheme, you'll have to do everything manually: including starting a timeout when you start a query and cancelling it if the query returns a result in time.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.