0

currently i develop an Ionic2 application which commuicates with a Firebase database. While updating a node sometimes it works and sometimes it doesn't. So i tired to handle the error with the following code:

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

But even if i disconnect my internet connection there is no error thrown. Does someone of you know how i could handle an error if the push was not successful?

Stevetro
  • 1,933
  • 3
  • 16
  • 29

2 Answers2

2

I had the same situation that push does not return promises sometime, so i raised issue on github FirebaseListObservable push() takes too long to add but unfortunately it was not resolved, I contacted firebase support through email, the support team reviewed my issue and checked the code i sent, and replied there is nothing to do in the code , and advised me to clear the phone's storage cache, i did the same and issue got resolved,

here is the mail from firebase support

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

rashidnk
  • 4,096
  • 2
  • 22
  • 32
1

If you would like to handle this you could consider setting a timeout because the Promise will just stay in 'pending' if Firebase doesn't return anything and resolve, reject / catch will never be triggered.

You could do this for example with Promise.race(): Example Promise timeout with Promise.race() also check this thread: More Examples

Community
  • 1
  • 1
louisvno
  • 669
  • 7
  • 17