How Does Or How Can You Effectively Handle Errors Using Firebase?
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 ca
Solution 1:
Firebase 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.
Solution 2:
You need to create a auth function that handles the errors. See the jsFiddle below for a great example.
function initAuth(ref) {
returnnew FirebaseSimpleLogin(ref, function (err, user) {
// if there is an error then display it if (err) {
displayError(err);
} elseif (user) {
// we only want to log people in through the email/password providerif( user.provider !== 'password' ) {
auth.logout();
}
else {
// logged in!
uid = user.uid;
// save the user to our firebaseref.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');
}
});
}
Post a Comment for "How Does Or How Can You Effectively Handle Errors Using Firebase?"