处理流星客户端的错误

时间:2015-08-10 09:14:38

标签: node.js meteor error-handling meteor-collection2

我目前正在使用meteor-collection2并且我的验证系统引发的错误存在问题。

在“lib”文件夹中,我定义了我的集合,并附加了SimpleSchema。然后,我定义了Meteor.method

# define methods
Meteor.methods
  # create
  RecipeCommentCreate: (options) ->
    # find recipe
    recipe = Recipes.findOne(options.recipeId)

    if !recipe
      throw new (Meteor.Error)(404, 'Recipe not found')

    # init comment
    comment =
      message: options.message
      recipe:
        _id: recipe._id

    # insert comment
    RecipeComments.insert(comment)

因此,此代码在client-sideserver-side上运行,以便使用延迟补偿(这是完美的,因为collection2可以在两端工作)。

但是,在调用此方法时(感谢客户端的事件):

# call method
Meteor.call 'RecipeCommentCreate', options, (error, result) ->
  if error
    # throw error
    Errors.throw error.reason
  else
    # reset form
    form.reset()

这不能以正确的方式工作,因为回调中的error只是服务器端抛出的错误。 customer2在客户端抛出的错误只是在我的浏览器控制台中登录,并且不会停止代码:

[Log] Exception while simulating the effect of invoking 'RecipeCommentCreate'  (meteor.js, line 890)

所以,如果有人可以帮助我以错误的方式理解我的所作所为...... 非常感谢,
雅尼斯

0 个答案:

没有答案
相关问题