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:
Girish Ramakrishnan
2021-08-19 12:32:23 -07:00
parent ada7166bf8
commit 4cd5137292
10 changed files with 176 additions and 244 deletions

View File

@@ -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) {