Skip to content

Instantly share code, notes, and snippets.

@themeteorchef
Last active August 29, 2015 14:13
Show Gist options
  • Save themeteorchef/ca55a9c3f66ef54994d9 to your computer and use it in GitHub Desktop.
Save themeteorchef/ca55a9c3f66ef54994d9 to your computer and use it in GitHub Desktop.
Handling exceptions on the server without a callback
// 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