em-wilson / book-node-mongodb-backbone

Example source code accompanying O'Reilly's "Building Node Applications with MongoDB and Backbone" by Mike Wilson
272 stars 119 forks source link

chap7 app.js app.get(/accounts/:id/activity) error for new account #40

Open abreups opened 10 years ago

abreups commented 10 years ago

When a (new) user registers, /accounts/:id/activity in app.js is called but the value of req.session.accountId is undefined and the application on the server crashes with an error (because models.Account.findById is called with accountId == undefined). This "only" happens for a new user; existing users don't cause this problem. I've been trying to debug what is going on here for a while, but no success. My error or book code error? If anyone could provide some feedback I'd appreciate.

conrado commented 10 years ago

I believe the author mentions in the book something about a bug that doesn't crash the server, however that's probably because he was using an old version of express. To fix this you should just add a check for the item, and res.send(400) if it doesn't exist or the item otherwise.