Closed beverlycodes closed 9 years ago
@ryanfields found a solution for this one? +1
@ryanfields @voidale struggling with this as well... did either of you manage this?
Thanks to @aramk's pull request, I've finally implemented this feature in 0.7.15
Here is a way to use it
MyCollection.before.update (userId, doc) ->
new Meteor.Error("message", "The user must be logged in to post a comment")
return false
# or this
MyCollection.before.update (userId, doc) ->
throw new Meteor.Error("message", "The user must be logged in to post a comment")
# or this
MyCollection.before.update (userId, doc) ->
throw new Error("Some error")
Is there any way to throw an error in a hook such that the original collection method's callback will get the error? I'm hoping to perform validations in before.insert and before.update. At the moment, I can't find any way to pass validation errors up to the callback of the original insert/update call. All I can seem to do is return false in the hook, which doesn't give the caller any info about why the method failed.