最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Best way to capture error from database firebase javascript - Stack Overflow

programmeradmin7浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 8

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 remend reading the Firebase reference documentation for finding more tidbits like this.

发布评论

评论列表(0)

  1. 暂无评论