【发布时间】:2014-02-17 09:22:53
【问题描述】:
我正在从 mongodb 检索模板集合的数据。所以我的问题是当我给出错误的templateName 时,程序应该会捕获错误。但事实并非如此。程序更进一步&我得到错误TypeError: Cannot read property 'subject' of null。
这件事情怎么处理?
Template.findOne({ name: templateName }, function (err, template) {
if (err) {
console.log('Error occured');
console.log(err.message);
callback(err);
}
else {
template_subject = template.subject;
template_html = template.dataMsg;
});
如果给出了错误的模板名称,我想将错误返回给回调函数。
【问题讨论】:
-
你可以在第8行之前查看
标签: javascript node.js mongodb angularjs