javascript - Destructuring promice callback -
there promice in code:
req.getvalidationresult() .then(result => { let errors = result.array(); if (errors.length) { return res.status(400).json({ errors: errors }); } return next(); });
i'd know there variants destructure 'result' variable on call (something .then({result.array(): errors} =>...
) , not make let errors = result.array();
assignment.
i believe impossible native promise. can change code bit:
req.getvalidationresult() .then(({array}) => array()) .then(errors => { if (errors.length) { return res.status(400).json({ errors: errors }); } return next(); });
or can use bluebird. has call
method:
req.getvalidationresult() .call('array') .then(errors => { if (errors.length) { return res.status(400).json({ errors: errors }); } return next(); });
but in case need cast promise bluebird promise
Comments
Post a Comment