Last active
August 29, 2015 14:13
-
-
Save themeteorchef/ca55a9c3f66ef54994d9 to your computer and use it in GitHub Desktop.
Handling exceptions on the server without a callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Accounts.createUser does NOT have a callback on the server, meaning we cannot get an error value and return it. If an error/exception does occur, how do we get it? | |
Meteor.methods(function(){ | |
createAccount: function(email, password){ | |
try { | |
// Note: we can only pass parameters to Accounts.createUser on the server, not a callback. | |
Accounts.createUser({email: email, password: password}); | |
} catch (exception) { | |
// Instead, using a try catch will allow us to "try" our Accounts.createUser method and if it throws an exception, it will | |
// "catch" the error, passing the exception to us as an argument. | |
console.log(exception); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment