How and how can you handle errors efficiently with firebase?

I read the firebase documentation and this is very asynchronous code that is used. I wanted to know if firebase throws errors and / or passes error data to callbacks. As far as I can tell, the documentation does not mention this. Thank you in advance for your consultation.

+7
source share
2 answers

Firebase does not currently produce developer consumption errors (with the exception of exceptions that occur for bad inputs). Firebase operations currently guarantee success or never fire events. In the event of network connectivity issues, Firebase simply does not fire events. This is the expected behavior, as Firebase is designed to work offline, and it will automatically lead you to speed after reconnecting.

Please note that in the future we will throw errors for security breaches and possibly other types of errors. An API to detect and handle these errors has not yet been written.

+5
source

You need to create an auth function that handles errors. See 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.net/firebase/wPBj5/embedded/result,js/

+1
source

All Articles