Skip to content

Instantly share code, notes, and snippets.

@izumskee
Last active August 29, 2015 14:26
Show Gist options
  • Save izumskee/b3eca69d2502ae1aee88 to your computer and use it in GitHub Desktop.
Save izumskee/b3eca69d2502ae1aee88 to your computer and use it in GitHub Desktop.
Smooth error handling for Meteor.methods
// in /lib needed on both client and server
var throwError = function(error, reason, details) {
error = new Meteor.Error(error, reason, details);
if (Meteor.isClient) {
return error;
} else if (Meteor.isServer) {
throw error;
}
};
// Some Method
Meteor.methods({
createPost: function(text) {
if (!this.userId) {
return throwError(403, 'Must be logged in');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment