The problem I see is that you car calling next() before you finish reading
the file.
But, I dont understand why you want to let know to the next middleware that
this one has fail?
I havent seen that a lot.. For instance lot of authentication code do
something along these lines:
function addUserToRequest(req, res, next) {
getUser(req.session.userId, function foo(err, user) {
if(err) {
return res.send(401); ///respond with unauthorized and do not
call the next middleware.
}
req.user = user; //put the user in the request object so the next
middleware can use it
next(); //call the next middleware.
});
}
2012/9/17 Aga <[email protected]>
> 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());
> }
>
--
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