Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to capture error from database firebase javascript

I have this code, but i don't know how capture a error.

  const coleccionRef = database.ref('test');
  coleccionRef.on('value', snapshot => {
    snapshot.val();
  });

Any idea?

like image 593
allel Avatar asked Aug 03 '26 09:08

allel


1 Answers

If your client doesn't have permission to read from the reference, Firebase will invoke the (optional) second callback that you can pass in to on(). E.g.

const coleccionRef = database.ref('test');
coleccionRef.on('value', snapshot => {
  snapshot.val();
}, error => {
    console.error(error);
});

I recommend reading the Firebase reference documentation for finding more tidbits like this.

like image 64
Frank van Puffelen Avatar answered Aug 05 '26 23:08

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!