I've got a tiny module that acts as a model for my data. It sits between my routes and my database for particular data (user data in my case).
I require this module in my route code, call the subscribe
method that it has, and that subscribes a user to a particular mailing list, by storing the needed data in my database. Yay!
My 'subscribe' method accepts an email and an email list ID as the two parameters. It's reasonable that I'll code sloppy and fast and put in an id for a list that doesn't exist. Spelling error, you name it.
How can I throw an error and point to the line number with that incorrect id?
Code from inside model/user.js:
if (emailLists.indexOf(listId) === -1) {
throw new Error('listId does not exist');
}
Code from inside route.js:
user.subscribe('[email protected]', 'knewsletterr', function (error, success) {
if (error) { return sendResponse(500, 'Ahhhhhhh!'); }
if (!error) { return sendResponse(200, 'subscribed'); }
});
Right now, I'm getting:
/home/.../project/models/user.js:85
if (emailLists.indexOf(listId) === -1) { throw new Error('listId does not exist'); }
^
Error: listId does not exist