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 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.

How to handle this thing?

  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;});   

If the wrong template name has been given, I want to return the error to the callback function.

Will not be back.

  Template.findOne ({name: templateName}, before using something like this, should test variable existence:  

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;

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -