Revert "fix: update usage of emailer.send to not catch (as errors are no longer thrown), email error throttler"

This reverts commit d4e5259fcf.
isekai-main
Julian Lam 3 years ago
parent e9588ca7b7
commit 165a1d8b76

@ -343,10 +343,6 @@ Emailer.sendToEmail = async (template, email, language, params) => {
return true;
} catch (err) {
if (Emailer._emailFailThrottle) {
return false;
}
if (err.code === 'ENOENT' && usingFallback) {
Emailer.fallbackNotFound = true;
winston.error(`[emailer/sendToEmail] ${await translator.translate('[[error:sendmail-not-found]]')}`);
@ -354,10 +350,6 @@ Emailer.sendToEmail = async (template, email, language, params) => {
winston.error(`[emailer/sendToEmail] ${err.message || err.code || 'Unknown error while sending email.'}`);
}
Emailer._emailFailThrottle = setTimeout(() => {
delete Emailer._emailFailThrottle;
}, 1000 * 60 * 5); // 5 minutes
return false;
}
};

@ -194,6 +194,7 @@ async function pushToUids(uids, notification) {
}
body = posts.relativeToAbsolute(body, posts.urlRegex);
body = posts.relativeToAbsolute(body, posts.imgRegex);
let errorLogged = false;
await async.eachLimit(uids, 3, async (uid) => {
await emailer.send('notification', uid, {
path: notification.path,
@ -203,6 +204,11 @@ async function pushToUids(uids, notification) {
body: body,
notification: notification,
showUnsubscribe: true,
}).catch((err) => {
if (!errorLogged) {
winston.error(`[emailer.send] ${err.stack}`);
errorLogged = true;
}
});
});
}

@ -90,7 +90,7 @@ SocketUser.reset.commit = async function (socket, data) {
username: username,
date: parsedDate,
subject: '[[email:reset.notify.subject]]',
});
}).catch(err => winston.error(`[emailer.send] ${err.stack}`));
};
SocketUser.isFollowing = async function (socket, data) {

@ -79,7 +79,7 @@ module.exports = function (User) {
subject: `[[email:welcome-to, ${meta.config.title || meta.config.browserTitle || 'NodeBB'}]]`,
template: 'registration_accepted',
uid: uid,
});
}).catch(err => winston.error(`[emailer.send] ${err.stack}`));
const total = await db.incrObjectFieldBy('registration:queue:approval:times', 'totalTime', Math.floor((Date.now() - creation_time) / 60000));
const counter = await db.incrObjectField('registration:queue:approval:times', 'counter');
await db.setObjectField('registration:queue:approval:times', 'average', total / counter);

@ -58,7 +58,7 @@ module.exports = function (User) {
until: until ? (new Date(until)).toUTCString().replace(/,/g, '\\,') : false,
reason: reason,
};
await emailer.send('banned', uid, data);
await emailer.send('banned', uid, data).catch(err => winston.error(`[emailer.send] ${err.stack}`));
return banData;
};

@ -103,6 +103,7 @@ Digest.send = async function (data) {
if (!data || !data.subscribers || !data.subscribers.length) {
return emailsSent;
}
let errorLogged = false;
await batch.processArray(data.subscribers, async (uids) => {
let userData = await user.getUsersFields(uids, ['uid', 'email', 'email:confirmed', 'username', 'userslug', 'lastonline']);
userData = userData.filter(u => u && u.email && (meta.config.includeUnverifiedEmails || u['email:confirmed']));
@ -141,6 +142,11 @@ Digest.send = async function (data) {
popularTopics: topics.popular,
interval: data.interval,
showUnsubscribe: true,
}).catch((err) => {
if (!errorLogged) {
winston.error(`[user/jobs] Could not send digest email\n[emailer.send] ${err.stack}`);
errorLogged = true;
}
});
}));
if (data.interval !== 'alltime') {

@ -59,7 +59,7 @@ UserReset.send = async function (email) {
subject: '[[email:password-reset-requested]]',
template: 'reset',
uid: uid,
});
}).catch(err => winston.error(`[emailer.send] ${err.stack}`));
return code;
};

Loading…
Cancel
Save