javascript - Node js error handling with callbacks in nested functions -


i know kind of error handling not right, promises should used instead, wondering if work is:

router.get('/main', function(req, res, next) { var mycallback = new function(err, data){     if(err) {         res.status(500).send({ error: "error (best handling ever)" });             return;         }             res.send("success");             return;     };     mainprocess(mycallback); });   function mainprocess(callback){     request.post(requestparams, function(error, response, body) {         if (error) {             console.log(error.message);             callback.return(error, "");         } else {             request.post(requestparams, function(error, response, body) {                 if (error) {                     console.log(error.message);                     callback.return(error, "");                 } else {                     // success                       callback.return(null, "success");                 }             });         }     }); } 

i test myself, need know whether callback passed parameter used in nested functions , whether it's right approach.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -