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