Detect firestore errors

Viewed 152

so i want a way to be able to detect this error inside my javascript code

@firebase/firestore: Firestore (7.19.1): FirebaseError: [code=resource-exhausted]: Quota exceeded.

i see it in the console , but the catch can't get it nor in try nor in then :/

try {
  // Your web app's Firebase configuration
  var firebaseConfig = {
    apiKey: "****VHhbGqI",
    authDomain: "****m-sum-235202.firebaseapp.com",
    databaseURL: "https://**'' '' m-sum-235202.firebaseio.com",
    projectId: "premium-sum-235202",
    storageBucket: "***'' '' 02.appspot.com",
    messagingSenderId: "428499848193",
    appId: "1:*******8193:web:520bc61504450a2e458400"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
console.log('daq')

console.log('daq2')
firebase.firestore().collection('testf').doc('test1').set({"zack9": firebase.firestore.FieldValue.increment(1)} , {merge: true }).then((data) => { alert(data) }).catch((error) => { alert('te') })
console.log('daq9')
} catch(error) {
console.log('daqaa')
console.log(error)
}

// tried this too

async function zack () {
try {
  // Your web app's Firebase configuration
  var firebaseConfig = {
    apiKey: "×**'' *****BHuNxsY5VHhbGqI",
    authDomain: "*'' '' '202.firebaseapp.com",
    databaseURL: "https://***' '' eio.com",
    projectId: "*****sum-235202",
    storageBucket: "**'*' '202.appspot.com",
    messagingSenderId: "**' *848193",
    appId: "1:428499848193:web:****20bc61504450a2e458400"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
console.log('daq')

console.log('daq2')
await firebase.firestore().collection('test').doc('test1').set({"zack9": firebase.firestore.FieldValue.increment(1)} , {merge: true })
console.log('daq9')
} catch(error) {
console.log('daqaa')
console.log(error)
}
}
zack()
1 Answers

Unfortunately, there is no way to track via code, errors related to quotas. As mentioned in the official documentation, related to pricing - accessible here - this information is only available via Console, as you mentioned, where you can track how much of your quota has already being used.

Considering that you are reaching a quota exceeded error, I would recommend you to give it a try limiting how much of reads and writes you will be doing to your database - actually, you would need to restrict any of the points from pricing that can cause you this error - so you avoid this type of error. There is a lot of ways to achieve, as using limit() method to restrict your calls, you can perform more specific queries to return less results, being more accurate on the information returned, etc. I would recommend you to take a look at this tutorial here, for good examples on this.

In addition to that, you can always create a Feature Request on Google's Issue Tracker, for availation about implementing this in the future.

Related