Error in Meteor.call


#1

I have this code in client

Template['product'].events
  'click .addcart': (event, template) ->
    event.preventDefault()
    add_this = {"item": 1, "name": "test", "qty": 5, "price": 124}
    Meteor.call "Carts.push", add_this
   return

and in server

Meteor.methods
  'Carts.push': (params) ->
    console.log params

every time e click the botton add cart I got an error in server side

Exception while invoking method 'Carts.push' Error: Did not check() all arguments during call to 'Carts.push'

Any idea why this error persist?


#2

I imagine it’s warning you to use the check() method to check that the parameters to the method are what you expected, such as a string or number or an object with the correct keys.


#3

Exactly ^. Your Meteor.method needs a check for params, so…

Meteor.methods
   'Carts.push': (params) ->
      check params, Object // Add this
      console.log params

#4

@jrudio @nkrisc Thanks! its now working


#5

that is weird, I never run the check() function and haven’t seen that error.
The few methods I use only take certain inputs so I can explicitly check for those.


#6

@cstrat I do not know if audit-argument-checks is a default package or not. If you do not want to check every params just remove audit-argument-checks package. See meteor doc about audit-argument-checks package


#7

I don’t know if this code is from your real code, but it is really not secure. Just send the id of the item and then the server will fetch the full item from the DB. Otherwise the client can call the method and set the price to 0$.


#8

It must not be a default package because like I said, never seen that error and I haven’t used check().


#9

@skini26 Yes your right. This is just for study proposes for now. No worries :smile: