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:
39
src/mail.js
39
src/mail.js
@@ -716,29 +716,26 @@ async function configureMail(mailFqdn, mailDomain, serviceConfig) {
|
||||
await shell.promises.exec('startMail', cmd);
|
||||
}
|
||||
|
||||
function getMailAuth(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
async function getMailAuth() {
|
||||
const dockerInspect = util.promisify(docker.inspect);
|
||||
|
||||
docker.inspect('mail', function (error, data) {
|
||||
if (error) return callback(error);
|
||||
const data = await dockerInspect('mail');
|
||||
const ip = safe.query(data, 'NetworkSettings.Networks.cloudron.IPAddress');
|
||||
if (!ip) throw new BoxError(BoxError.MAIL_ERROR, 'Error querying mail server IP');
|
||||
|
||||
const ip = safe.query(data, 'NetworkSettings.Networks.cloudron.IPAddress');
|
||||
if (!ip) return callback(new BoxError(BoxError.MAIL_ERROR, 'Error querying mail server IP'));
|
||||
// extract the relay token for auth
|
||||
const env = safe.query(data, 'Config.Env', null);
|
||||
if (!env) throw new BoxError(BoxError.MAIL_ERROR, 'Error getting mail env');
|
||||
const tmp = env.find(function (e) { return e.indexOf('CLOUDRON_RELAY_TOKEN') === 0; });
|
||||
if (!tmp) throw new BoxError(BoxError.MAIL_ERROR, 'Error getting CLOUDRON_RELAY_TOKEN env var');
|
||||
const relayToken = tmp.slice('CLOUDRON_RELAY_TOKEN'.length + 1); // +1 for the = sign
|
||||
if (!relayToken) throw new BoxError(BoxError.MAIL_ERROR, 'Error parsing CLOUDRON_RELAY_TOKEN');
|
||||
|
||||
// extract the relay token for auth
|
||||
const env = safe.query(data, 'Config.Env', null);
|
||||
if (!env) return callback(new BoxError(BoxError.MAIL_ERROR, 'Error getting mail env'));
|
||||
const tmp = env.find(function (e) { return e.indexOf('CLOUDRON_RELAY_TOKEN') === 0; });
|
||||
if (!tmp) return callback(new BoxError(BoxError.MAIL_ERROR, 'Error getting CLOUDRON_RELAY_TOKEN env var'));
|
||||
const relayToken = tmp.slice('CLOUDRON_RELAY_TOKEN'.length + 1); // +1 for the = sign
|
||||
if (!relayToken) return callback(new BoxError(BoxError.MAIL_ERROR, 'Error parsing CLOUDRON_RELAY_TOKEN'));
|
||||
|
||||
callback(null, {
|
||||
ip,
|
||||
port: constants.INTERNAL_SMTP_PORT,
|
||||
relayToken
|
||||
});
|
||||
});
|
||||
return {
|
||||
ip,
|
||||
port: constants.INTERNAL_SMTP_PORT,
|
||||
relayToken
|
||||
};
|
||||
}
|
||||
|
||||
function restartMail(callback) {
|
||||
@@ -1134,7 +1131,7 @@ async function sendTestMail(domain, to) {
|
||||
const result = await getDomain(domain);
|
||||
if (!result) throw new BoxError(BoxError.NOT_FOUND, 'mail domain not found');
|
||||
|
||||
await util.promisify(mailer.sendTestMail)(result.domain);
|
||||
await mailer.sendTestMail(result.domain);
|
||||
}
|
||||
|
||||
async function listMailboxes(domain, search, page, perPage) {
|
||||
|
||||
Reference in New Issue
Block a user