Thursday, 18 May 2017

nodejs express sendStatus in promise using messageBus

Here is my API call, im trying to send different status depending on the event message from my msgbus. But what i recieve is Internal Server Error and the server crashes.

router.route('/').post(function(req,res){
    msgbus.emitCommand({
      command: cmd,
      aggregate: {
          name: aggregateName
      },
      payload: req.body
    });
    msgbus.onEvent(function(ev){
       //console.log(ev.event) -> 'commandReject'
       if(ev.event === 'commandReject') res.sendStatus(500);
       else res.sendStatus(200);
    })
    //res.sendStatus(200);
});

I think res.sendStatus must be in promise of the onEvent method. But how to achieve that.



via Georgi Antonov

No comments:

Post a Comment