javascript - TypeError: Cannot read property 'subject' of null -
I am retrieving the data from the template archive from mongodb. So my problem occurs when I give an incorrect How to handle this thing? If the wrong template name has been given, I want to return the error to the callback function. Will not be back. function (mistake, template) {If (fault === faucet & amp; template == faucet} {// there is no error, but no result was found err = new error (templateName + 'not found');}) {Console.log ('An error occurred'); Console.log (err.message); // Quick return to avoid another indentation :) Return callback (mistake); } Template_subject = template.subject; Template_html = template.dataMsg; templateName , this program is considered to catch an error but it does not do that the program goes ahead & amp; I get the error
TypeError: Properties of the zero 'subject' can not be read.
Template.findOne ({name: templateName}, function (mistake, template) {if (err) {console.log ('an error occurred'); console.log (err.message) ; Callback (mistake);} and {template_subject = template.subject; template_html = template.dataMsg;});
Template.findOne ({name: templateName}, before using something like this, should test variable existence:
Comments
Post a Comment