Last active
August 29, 2015 14:26
-
-
Save izumskee/b3eca69d2502ae1aee88 to your computer and use it in GitHub Desktop.
Smooth error handling for Meteor.methods
This file contains hidden or 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
// 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