From 5be9dd258719d3969efb0f5604df4b185944fa4f Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Sun, 26 Apr 2015 23:19:03 -0700 Subject: [PATCH] gracefully handle original story poster having been deleted in mailer --- controllers/story.js | 52 +++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/controllers/story.js b/controllers/story.js index 1f1bf90247..aedd263cc3 100755 --- a/controllers/story.js +++ b/controllers/story.js @@ -517,33 +517,35 @@ exports.storySubmission = function(req, res, next) { if (err) { return next(err); } - // If the emails of both authors differ, only then proceed with email notification - if (data.author.email && (data.author.email !== recipient.email)) { - var transporter = nodemailer.createTransport({ - service: 'Mandrill', - auth: { - user: secrets.mandrill.user, - pass: secrets.mandrill.password - } - }); + if (recipient && recipient.email) { + // If the emails of both authors differ, only then proceed with email notification + if (data.author.email && (data.author.email !== recipient.email)) { + var transporter = nodemailer.createTransport({ + service: 'Mandrill', + auth: { + user: secrets.mandrill.user, + pass: secrets.mandrill.password + } + }); - var mailOptions = { - to: recipient.email, - from: 'Team@freecodecamp.com', - subject: data.author.username + ' replied to your post on Camper News', - text: [ - 'Just a quick heads-up: ' + data.author.username + ' replied to you on Camper News.', - 'You can keep this conversation going.', - 'Just head back to the discussion here: http://freecodecamp.com/stories/' + data.originalStoryLink, - '- the Free Code Camp Volunteer Team' - ].join('\n') - }; + var mailOptions = { + to: recipient.email, + from: 'Team@freecodecamp.com', + subject: data.author.username + ' replied to your post on Camper News', + text: [ + 'Just a quick heads-up: ' + data.author.username + ' replied to you on Camper News.', + 'You can keep this conversation going.', + 'Just head back to the discussion here: http://freecodecamp.com/stories/' + data.originalStoryLink, + '- the Free Code Camp Volunteer Team' + ].join('\n') + }; - transporter.sendMail(mailOptions, function (err) { - if (err) { - return err; - } - }); + transporter.sendMail(mailOptions, function (err) { + if (err) { + return err; + } + }); + } } }); });