javascript - Meteor SimpleSchema + Methods : clicking too fast throw an error -
first, have schema:
rides = new mongo.collection('rides'); rides.attachschema( new simpleschema({ name:{type:string}, 'passengers.$._id': { type: string, autovalue: function(){ if(this.isupdate && this.operator !== '$pull') return this.userid; else this.unset(); } }, 'passengers.$.validate':{type:boolean}, );
server side, have these methods:
meteor.methods({ leaveride: function(_id){ check(_id, string); rides.update(_id, { $pull:{passengers:{ _id:this.userid }} }); }, joinride: function(_id){ check(_id, string); rides.update(_id, { $addtoset: {passengers: {validate:true}} }); } });
and finally, 2 buttons join
, leave
call:
template.ride.events({ 'click .join': function(e){ meteor.call('joinride', this.ride._id); }, 'click .leave': function(e){ meteor.call('leaveride', this.ride._id); }, });
it works fine, problem when click fast on buttons (one after another), seems queries don't have time process , get:
client-side (either of these):
error invoking method 'leaveride': internal server error [500]
error invoking method 'joinride': id required [400]
server-side (either of these):
exception while invoking method 'leaveride' error: did not check() arguments during call 'leaveride'
exception while invoking method 'joinride' error: id required
after hours of investigation, turned out easy security package preventing calls when clicking faster 500ms between clicks (security against ddos).
Comments
Post a Comment