admin管理员组文章数量:1387332
I've been reading the firebase documentation and it is very much asynchronous code that is used. I wanted to know if firebase is throwing errors and/or passing error data in the callbacks. As far as I can tell, the documentation makes no mention of it. Thanks in advance for advice
I've been reading the firebase documentation and it is very much asynchronous code that is used. I wanted to know if firebase is throwing errors and/or passing error data in the callbacks. As far as I can tell, the documentation makes no mention of it. Thanks in advance for advice
Share Improve this question asked Jul 12, 2012 at 18:54 ReinsbrainReinsbrain 2,6012 gold badges27 silver badges39 bronze badges2 Answers
Reset to default 5Firebase doesn't produce developer-consumable errors at the moment (outside exceptions that are thrown for bad inputs). Currently Firebase operations are guaranteed to either succeed or never trigger events. In the case of network connectivity issues, Firebase will simply not trigger events. This is expected behaviour, as Firebase is designed to work in offline mode, and it will automatically bring you up to speed once a connection has been re-established.
Note that in the future we will throw errors for security violations and possibly other error types. The API for catching and handling these errors has not been written yet.
You need to create a auth function that handles the errors. See the jsFiddle below for a great example.
function initAuth(ref) {
return new FirebaseSimpleLogin(ref, function (err, user) {
// if there is an error then display it
if (err) {
displayError(err);
} else if (user) {
// we only want to log people in through the email/password provider
if( user.provider !== 'password' ) {
auth.logout();
}
else {
// logged in!
uid = user.uid;
// save the user to our firebase
ref.child(user.uid).set({
id: user.id,
uid: user.uid,
email: user.email
});
// switch over the the user info screen
switchView('userInfo');
}
} else {
// logged out!
console.log('not logged in');
}
});
}
http://jsfiddle/firebase/wPBj5/embedded/result,js/
本文标签: javascriptHow does or how can you effectively handle errors using firebaseStack Overflow
版权声明:本文标题:javascript - How does or how can you effectively handle errors using firebase? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744528882a2610908.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论