From e25c0313d1a5868bfcdb370ea34e71eb040baa97 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 28 Jan 2022 15:26:10 -0500 Subject: [PATCH] Revert "refactor: emailer.send and emailer.sendToEmail returns Boolean based on message being successfully sent" This reverts commit f0e32ff182c08c679a569a7dc7f821848d3ebbba. --- src/emailer.js | 18 ++++++------------ test/emailer.js | 10 ++++++---- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/emailer.js b/src/emailer.js index 25e598776c..36cab7d692 100644 --- a/src/emailer.js +++ b/src/emailer.js @@ -238,7 +238,7 @@ Emailer.send = async (template, uid, params) => { if (process.env.NODE_ENV === 'development') { winston.warn(`uid : ${uid} has no email, not sending "${template}" email.`); } - return false; + return; } const allowedTpls = ['verify-email', 'welcome', 'registration_accepted', 'reset', 'reset_notify']; @@ -246,7 +246,7 @@ Emailer.send = async (template, uid, params) => { if (process.env.NODE_ENV === 'development') { winston.warn(`uid : ${uid} (${userData.email}) has not confirmed email, not sending "${template}" email.`); } - return false; + return; } const userSettings = await User.getSettings(uid); // Combined passed-in payload with default values @@ -262,10 +262,9 @@ Emailer.send = async (template, uid, params) => { }); if (result.cancel) { - return false; + return; } - - return Emailer.sendToEmail(template, userData.email, userSettings.userLang, params); + await Emailer.sendToEmail(template, userData.email, userSettings.userLang, params); }; Emailer.sendToEmail = async (template, email, language, params) => { @@ -340,17 +339,13 @@ Emailer.sendToEmail = async (template, email, language, params) => { } else { await Emailer.sendViaFallback(data); } - - return true; } catch (err) { if (err.code === 'ENOENT' && usingFallback) { Emailer.fallbackNotFound = true; - winston.error(`[emailer/sendToEmail] ${await translator.translate('[[error:sendmail-not-found]]')}`); + throw new Error('[[error:sendmail-not-found]]'); } else { - winston.error(`[emailer/sendToEmail] ${err.message || err.code || 'Unknown error while sending email.'}`); + throw err; } - - return false; } }; @@ -365,7 +360,6 @@ Emailer.sendViaFallback = async (data) => { winston.verbose(`[emailer] Sending email to uid ${data.uid} (${data.to})`); await Emailer.fallbackTransport.sendMail(data); - return true; }; Emailer.renderAndTranslate = async (template, params, lang) => { diff --git a/test/emailer.js b/test/emailer.js index 87d893dc50..d39f6068f6 100644 --- a/test/emailer.js +++ b/test/emailer.js @@ -47,7 +47,7 @@ describe('emailer', () => { // TODO: test sendmail here at some point - it('plugin hook should work', async () => { + it('plugin hook should work', (done) => { const error = new Error(); Plugins.hooks.register('emailer-test', { @@ -61,10 +61,12 @@ describe('emailer', () => { }, }); - const success = await Emailer.sendToEmail(template, email, language, params); - assert.strictEqual(success, false); + Emailer.sendToEmail(template, email, language, params, (err) => { + assert.equal(err, error); - Plugins.hooks.unregister('emailer-test', 'filter:email.send'); + Plugins.hooks.unregister('emailer-test', 'filter:email.send'); + done(); + }); }); it('should build custom template on config change', (done) => {