fixed handling of redis.exec

This commit is contained in:
Andris Reinman 2017-10-03 13:09:16 +03:00
parent a5ddfa0979
commit a36311c2df
3 changed files with 16 additions and 7 deletions

View file

@ -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,

View file

@ -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);
}

View file

@ -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);
});
});