From a36311c2df6338295a6a0f2fcc036cb2aae97df4 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Tue, 3 Oct 2017 13:09:16 +0300 Subject: [PATCH] fixed handling of redis.exec --- lib/api/users.js | 11 +++++++---- lib/autoreply.js | 6 ++++-- lib/tools.js | 6 +++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/api/users.js b/lib/api/users.js index 0b76a83d..fa5f5562 100644 --- a/lib/api/users.js +++ b/lib/api/users.js @@ -5,6 +5,7 @@ const Joi = require('joi'); const MongoPaging = require('mongo-cursor-pagination'); const ObjectID = require('mongodb').ObjectID; const tools = require('../tools'); +const errors = require('../errors'); const openpgp = require('openpgp'); const addressparser = require('addressparser'); const libmime = require('libmime'); @@ -289,15 +290,17 @@ module.exports = (db, server, userHandler) => { .exec((err, result) => { if (err) { // ignore + errors.notify(err, { userId: user }); } + let recipients = Number(userData.recipients) || config.maxRecipients; let forwards = Number(userData.forwards) || config.maxForwards; - let recipientsSent = Number(result && result[0]) || 0; - let recipientsTtl = Number(result && result[1]) || 0; + let recipientsSent = Number(result && result[0] && result[0][1]) || 0; + let recipientsTtl = Number(result && result[1] && result[1][1]) || 0; - let forwardsSent = Number(result && result[2]) || 0; - let forwardsTtl = Number(result && result[3]) || 0; + let forwardsSent = Number(result && result[2] && result[2][1]) || 0; + let forwardsTtl = Number(result && result[3] && result[3][1]) || 0; res.json({ success: true, diff --git a/lib/autoreply.js b/lib/autoreply.js index 83569a3a..d888fe22 100644 --- a/lib/autoreply.js +++ b/lib/autoreply.js @@ -4,6 +4,7 @@ const MailComposer = require('nodemailer/lib/mail-composer'); const MessageSplitter = require('./message-splitter'); const db = require('./db'); const consts = require('./consts'); +const errors = require('./errors'); const maildrop = require('./maildrop'); module.exports = (options, callback) => { @@ -55,12 +56,13 @@ module.exports = (options, callback) => { .zremrangebyscore('war:' + options.userData._id, '-inf', Date.now() - consts.MAX_AUTOREPLY_INTERVAL) // add enw entry if not present .zadd('war:' + options.userData._id, 'NX', Date.now(), options.sender) - .exec((err, response) => { + .exec((err, result) => { if (err) { + errors.notify(err, { userId: options.userData._id }); return callback(null, false); } - if (!response || !response[1]) { + if (!result || !result[1] || !result[1][1]) { // already responded return callback(null, false); } diff --git a/lib/tools.js b/lib/tools.js index 4b21f9a8..69cfc6e7 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -4,6 +4,7 @@ const os = require('os'); const punycode = require('punycode'); const libmime = require('libmime'); const consts = require('./consts'); +const errors = require('./errors'); const fs = require('fs'); const he = require('he'); const pathlib = require('path'); @@ -134,7 +135,10 @@ function getMailboxCounter(db, mailbox, type, done) { .multi() .set(prefix + ':' + mailbox.toString(), sum) .expire(prefix + ':' + mailbox.toString(), consts.MAILBOX_COUNTER_TTL) - .exec(() => { + .exec(err => { + if (err) { + errors.notify(err); + } done(null, sum); }); });