From 22431a4ea2c65d7b3d24721dc769606a1aaf4e79 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 9 Jun 2021 15:45:54 +0100 Subject: [PATCH] Updating SMTP config to show better errors. --- .../builder/portal/manage/email/index.svelte | 18 +++++++++++------- .../src/api/controllers/admin/configs.js | 16 ++++++++++------ .../worker/src/api/routes/admin/configs.js | 1 - packages/worker/src/utilities/email.js | 6 ++---- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/email/index.svelte b/packages/builder/src/pages/builder/portal/manage/email/index.svelte index 44442767a8..46af44ec93 100644 --- a/packages/builder/src/pages/builder/portal/manage/email/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/email/index.svelte @@ -38,17 +38,21 @@ let loading async function saveSmtp() { - try { - // Save your SMTP config - const response = await api.post(`/api/admin/configs`, smtpConfig) + // Save your SMTP config + const response = await api.post(`/api/admin/configs`, smtpConfig) + + if (response.status !== 200) { + const error = await response.text() + let message = error + try { + message = JSON.parse(error).message + } catch (err) {} + notifications.error(`Failed to save email settings, reason: ${message}`) + } else { const json = await response.json() - if (response.status !== 200) throw new Error(json.message) smtpConfig._rev = json._rev smtpConfig._id = json._id - notifications.success(`Settings saved.`) - } catch (err) { - notifications.error(`Failed to save email settings. ${err}`) } } diff --git a/packages/worker/src/api/controllers/admin/configs.js b/packages/worker/src/api/controllers/admin/configs.js index 82466249a2..e1bd385384 100644 --- a/packages/worker/src/api/controllers/admin/configs.js +++ b/packages/worker/src/api/controllers/admin/configs.js @@ -27,11 +27,15 @@ exports.save = async function (ctx) { }) } - // verify the configuration - switch (type) { - case Configs.SMTP: - await email.verifyConfig(config) - break + try { + // verify the configuration + switch (type) { + case Configs.SMTP: + await email.verifyConfig(config) + break + } + } catch (err) { + ctx.throw(400, err) } try { @@ -42,7 +46,7 @@ exports.save = async function (ctx) { _rev: response.rev, } } catch (err) { - ctx.throw(err.status, err) + ctx.throw(400, err) } } diff --git a/packages/worker/src/api/routes/admin/configs.js b/packages/worker/src/api/routes/admin/configs.js index 09b8f97f84..c388b83456 100644 --- a/packages/worker/src/api/routes/admin/configs.js +++ b/packages/worker/src/api/routes/admin/configs.js @@ -14,7 +14,6 @@ function smtpValidation() { host: Joi.string().required(), from: Joi.string().email().required(), secure: Joi.boolean().optional(), - selfSigned: Joi.boolean().optional(), auth: Joi.object({ type: Joi.string().valid("login", "oauth2", null), user: Joi.string().required(), diff --git a/packages/worker/src/utilities/email.js b/packages/worker/src/utilities/email.js index 778ad8af4b..4e48844843 100644 --- a/packages/worker/src/utilities/email.js +++ b/packages/worker/src/utilities/email.js @@ -27,10 +27,8 @@ function createSMTPTransport(config) { secure: config.secure || false, auth: config.auth, } - if (config.selfSigned) { - options.tls = { - rejectUnauthorized: false, - } + options.tls = { + rejectUnauthorized: false, } } else { options = {