vendredi 19 octobre 2018

firebase firestore - how to check an error in the catch

I want to catch a firestore error and execute code based on what kind of error it is. (My database is build that if a document doesn't exist you won't be able to access it and therefore I have been getting a lot of permission-denied errors for non-existent documents. My solution is to check the error and create a document if I get a permission denied error.)

This is my current code:

            userDataDocRef.collection('emailPreferences').doc('main').get().then(function(doc) {
          if (doc.exists) {
            var data = doc.data();
            console.log(data);
            var getGameUpdates = data.getGameUpdates;
            switchEmailNewGames.checked = getGameUpdates;
          } else {

          }
        }).catch(function(error) {
          console.log(error)
          if (error == firebase.firestore.FirestoreError.permission-denied) {
            console.log('FIREBASE PERMISSION DENIED ERROR')
          }
        })

My Question: How do I check what kind of error I got properly? (what I have at the moment doesn't work)

Thank you for your help!




Aucun commentaire:

Enregistrer un commentaire