javascript - Render Jade view without Response Object -


i have complex chain of async callbacks , during point in chain, if there's error, i'd render jade template error message.

in function partnererr below, possible respond template without original response object?

app.post('/dashboard/partners/create', function (req, res) {     console.log( req.body );      parseutils.doesuserexist(          req.body.partneremail,          function() { shopifyutils.doespartnerexist( req.body.partnershopslug,                  function() { parseutils.createuser( req.body,                      function() { shopifyutils.createpartner( req.body,                          res.send( ' good. parse , shopify passed. user created. '),                         partnererr                     ); },                     partnererr                  ); },                 partnererr             );          },         partnererr     ); });  function partnererr(err) {     console.log( 'rendering partner error' );     app.render('admin/partnerscreate', { error : err }, function(err, html) {         console.log('html', html);     }); } 

firstly, take @ https://github.com/caolan/async clean series of async calls. many nested unreadable. looks series or waterfall suite needs here. drastically cut down number of times need write partnererr , move of error checking logic 1 place.

that being said, why not pass res partnererr , use res.render? understanding question correctly?

update

i encourage consider rewriting said above, however, if want leave alone, this:

app.post('/dashboard/partners/create', function(req, res) {   console.log(req.body);    parseutils.doesuserexist(     req.body.partneremail,     function() {       shopifyutils.doespartnerexist(req.body.partnershopslug,         function() {           parseutils.createuser(req.body,             function() {               shopifyutils.createpartner(req.body,                 res.send(' good. parse , shopify passed. user created. '),                 partnererr(res)               );             },             partnererr(res)           );         },         partnererr(res)       );     },     partnererr(res)   ); });  function partnererr(res) {   return function(err) {     console.log('rendering partner error');     res.render('admin/partnerscreate', {       error: err     });   } } 

another option move partnererr function same scope app.post , have access res variable. i'm not sure how decoupled partnererr based on snippet.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -