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?
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?
Share Improve this question edited Dec 5, 2017 at 15:34 Frank van Puffelen 601k85 gold badges890 silver badges860 bronze badges asked Dec 5, 2017 at 11:09 allelallel 8771 gold badge12 silver badges22 bronze badges 1-
1
you may check that you have a data or empty with
if(snapshot.exists()) { // do something with data } else {//there is no data}
firebase.google./docs/reference/js/… – Cappittall Commented Dec 5, 2017 at 11:17
1 Answer
Reset to default 8If 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 remend reading the Firebase reference documentation for finding more tidbits like this.