mailer: fix error handling
previous mailer code has no callback and thus no way to pass back errors. now with asyncification it passes back the error
This commit is contained in:
@@ -7,7 +7,7 @@ exports = module.exports = {
|
||||
getCloudronAvatar
|
||||
};
|
||||
|
||||
var assert = require('assert'),
|
||||
const assert = require('assert'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
@@ -15,44 +15,40 @@ var assert = require('assert'),
|
||||
settings = require('../settings.js'),
|
||||
_ = require('underscore');
|
||||
|
||||
function getFooter(req, res, next) {
|
||||
settings.getFooter(function (error, footer) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
async function getFooter(req, res, next) {
|
||||
const [error, footer] = await safe(settings.getFooter());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { footer }));
|
||||
});
|
||||
next(new HttpSuccess(200, { footer }));
|
||||
}
|
||||
|
||||
function setFooter(req, res, next) {
|
||||
async function setFooter(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.footer !== 'string') return next(new HttpError(400, 'footer is required'));
|
||||
|
||||
settings.setFooter(req.body.footer, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error] = await safe(settings.setFooter(req.body.footer));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
});
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
function setCloudronName(req, res, next) {
|
||||
async function setCloudronName(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.name !== 'string') return next(new HttpError(400, 'name is required'));
|
||||
|
||||
settings.setCloudronName(req.body.name, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error] = await safe(settings.setCloudronName(req.body.name));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, {}));
|
||||
});
|
||||
next(new HttpSuccess(202, {}));
|
||||
}
|
||||
|
||||
function getCloudronName(req, res, next) {
|
||||
settings.getCloudronName(function (error, name) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
async function getCloudronName(req, res, next) {
|
||||
const [error, name] = await safe(settings.getCloudronName());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { name: name }));
|
||||
});
|
||||
next(new HttpSuccess(200, { name }));
|
||||
}
|
||||
|
||||
async function setAppstoreListingConfig(req, res, next) {
|
||||
|
||||
@@ -63,7 +63,7 @@ async function login(req, res, next) {
|
||||
|
||||
eventlog.add(eventlog.ACTION_USER_LOGIN, auditSource, { userId: req.user.id, user: users.removePrivateFields(req.user) });
|
||||
|
||||
await safe(users.notifyLoginLocation(req.user, ip, userAgent, auditSource));
|
||||
safe(users.notifyLoginLocation(req.user, ip, userAgent, auditSource));
|
||||
|
||||
next(new HttpSuccess(200, token));
|
||||
}
|
||||
|
||||
@@ -120,17 +120,16 @@ async function setMailEnabled(req, res, next) {
|
||||
next(new HttpSuccess(202));
|
||||
}
|
||||
|
||||
function sendTestMail(req, res, next) {
|
||||
async function sendTestMail(req, res, next) {
|
||||
assert.strictEqual(typeof req.params.domain, 'string');
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (!req.body.to || typeof req.body.to !== 'string') return next(new HttpError(400, 'to must be a non-empty string'));
|
||||
|
||||
mail.sendTestMail(req.params.domain, req.body.to, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error] = await safe(mail.sendTestMail(req.params.domain, req.body.to));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202));
|
||||
});
|
||||
next(new HttpSuccess(202));
|
||||
}
|
||||
|
||||
async function listMailboxes(req, res, next) {
|
||||
|
||||
Reference in New Issue
Block a user