Tuesday 12 January 2016

Socket IO return error

I can't seem to figure out a good way to return errors in socket io.(Pardon the CoffeeScript)Currently, from the client side I'm emitting and expecting a callbacksocket.emit "recruit", type: "Spear", recruitAmount: spearMenRecruitCount, (callback) -> console.log "Callback: ", callback And on the server side I'm checking that all needed variables were sentsocket.on 'recruit', (data, cb) -> return cb error: true, message: "Missing Troop Recruit Count" if !data.recruitAmount? return cb error: true, message: "Missing Troop Recruit Type" if !data.type? return cb error: true, message: "Missing Village ID" if !data.villageID? Is there a better way to do this?

Submitted January 13, 2016 at 02:32AM by hego555

No comments:

Post a Comment