Skip to content

Node.js based forum software built for the modern web

fix: closes #12795, don't crash if there is an error in auto approve from queue

Barış Soner Uşaklı6ccf40bf6fd8
diff --git a/src/user/approval.js b/src/user/approval.js
index 5e0f1153c0..5067239d8a 100644
--- a/src/user/approval.js
+++ b/src/user/approval.js
@@ -14,8 +14,12 @@ const slugify = require('../slugify');
const plugins = require('../plugins');
module.exports = function (User) {
- new cronJob('0 * * * *', (() => {
- User.autoApprove();
+ new cronJob('0 * * * *', (async () => {
+ try {
+ await User.autoApprove();
+ } catch (err) {
+ winston.error(err.stack);
+ }
}), null, true);
User.addToApprovalQueue = async function (userData) {
@@ -160,8 +164,14 @@ module.exports = function (User) {
const users = await db.getSortedSetRevRangeWithScores('registration:queue', 0, -1);
const now = Date.now();
for (const user of users.filter(user => now - user.score >= meta.config.autoApproveTime * 3600000)) {
- // eslint-disable-next-line no-await-in-loop
- await User.acceptRegistration(user.value);
+ try {
+ // eslint-disable-next-line no-await-in-loop
+ await User.acceptRegistration(user.value);
+ } catch (err) {
+ winston.error(err.stack);
+ // eslint-disable-next-line no-await-in-loop
+ await removeFromQueue(user.value);
+ }
}
};
};