First of all try to organize your code a little better, that will help you. Try not to have more than 3 levels of indentation whenever possible. I assume you are using expressjs? If so, then you just need to call next() to call the next middleware. If you do with new Error() as the only arg, then I think it will call the next function(err, req, res, next) in the stack, but you can check con expressjs.com if you want to be 100% sure about this.
2012/9/17 Aga <[email protected]> > Hi, > > I'm a Node.js newbie and have a middleware related question. Here is the > code: > > > // router starts controller() > ... > exports.controller = function controller(req, res, next) { > model.getFileData("/tmp/foo.txt", function foo(err, data) { > if(err) { > console.log("error while reading file"); > return(next(new Error()); *// exits foo() and NOT controller()* > } > console.log("success"); > // do something with data > }); > return(next()); > } > > > If the model returns an error, I want to call controllers next() to jump > to the next middleware function. > I'm not sure how to organize the code, could you give me some examples? > > Thank you > Aga > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
