Chuck O
Chuck O

Reputation: 25

firebase 3/AngularFire 2 cannot catch error when trying to set firebase

Firebase v3.2.1 AngularFire 2.0.1

I try to set firebase, I got this error:

Error: Firebase.set failed: First argument contains undefined in property 'products.xxx.longDescFR'

but I cannot catch the error, no console log displayed!

firebase.database().ref('products').set(productList).then(function(ref) {
      console.log(ref)
    }).catch(function(error) {
      console.log('Failed: ' + error);
    });

any idea how to catch the reject/fail promise?

Chuck

Upvotes: 0

Views: 1415

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

The catch() clause is called when the write fails on the server, so when the security rules reject the operation.

When you're passing in undefined, the operation already fails on the client. You could probably try catch it, but it's way better to simply detect the undefined and not write:

if (productList) {
    firebase.database().ref('products').set(productList).then(function(ref) {
      console.log(ref)
    }).catch(function(error) {
      console.log('Failed: ' + error);
    });
}

Upvotes: 2

Related Questions