Hen Eliezer
Hen Eliezer

Reputation: 11

Firebase doesn't catch error ( When pushing json offline )

I'm trying to make an alert window saying there's an error, When trying to post a message offline. But the catch doesn't seem to ever work, Maybe it just works in other cases? here's my code :

  return (dispatch) => {
    dispatch({
      type: POST_TO_DB,
    });
    firebase.database().ref(locationInDB).push(object)
    .then((data) => {
      dispatch({
        type: POST_TRADE_TO_DB_SUCCESS,
      }); // success
    })
    .catch((err) => {
      console.log("failed to post...")
      dispatch({
        type: POST_TRADE_TO_DB_FAILED,
      }); // failed
    });
  };

Is there an alternative? Or am I doing something wrong?

Upvotes: 0

Views: 470

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598901

When there is no network connection, the Firebase client will keep the pending write in memory until the network connection is restored, at which point it will complete the write.

The catch() clause is triggered if the write fails on the server, not when it can't complete.

Also see:

Upvotes: 1

Related Questions