From c84b51d4aedcfb78a2c3a2a02ff814c8e9d37e68 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 19 Nov 2014 21:19:12 +0530 Subject: [PATCH] FEATURE: show exact error for test email --- .../admin/controllers/admin-email-index.js.es6 | 8 ++++++-- app/controllers/admin/email_controller.rb | 8 ++++++-- config/environments/development.rb | 1 - config/locales/client.en.yml | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/admin-email-index.js.es6 b/app/assets/javascripts/admin/controllers/admin-email-index.js.es6 index 58eff83cd26..341ca4f652b 100644 --- a/app/assets/javascripts/admin/controllers/admin-email-index.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-email-index.js.es6 @@ -36,8 +36,12 @@ export default DiscourseController.extend({ data: { email_address: this.get('testEmailAddress') } }).then(function () { self.set('sentTestEmail', true); - }).catch(function () { - bootbox.alert(I18n.t('admin.email.test_error')); + }, function(e) { + if (e.responseJSON && e.responseJSON.errors) { + bootbox.alert(I18n.t('admin.email.error', { server_error: e.responseJSON.errors[0] })); + } else { + bootbox.alert(I18n.t('admin.email.test_error')); + } }).finally(function() { self.set('sendingEmail', false); }); diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb index 8d706b7c033..0a8e3d32353 100644 --- a/app/controllers/admin/email_controller.rb +++ b/app/controllers/admin/email_controller.rb @@ -9,8 +9,12 @@ class Admin::EmailController < Admin::AdminController def test params.require(:email_address) - Jobs::TestEmail.new.execute(to_address: params[:email_address]) - render nothing: true + begin + Jobs::TestEmail.new.execute(to_address: params[:email_address]) + render nothing: true + rescue => e + render json: {errors: [e.message]}, status: 422 + end end def all diff --git a/config/environments/development.rb b/config/environments/development.rb index dd225cf9907..160ee7dc688 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -52,4 +52,3 @@ Discourse::Application.configure do config.developer_emails = emails.split(",").map(&:strip) end end - diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 5e5810ef192..5d7369364e9 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1760,6 +1760,7 @@ en: settings: "Settings" all: "All" sending_test: "Sending test Email..." + error: "ERROR - %{server_error}" test_error: "There was a problem sending the test email. Please double-check your mail settings, verify that your host is not blocking mail connections, and try again." sent: "Sent" skipped: "Skipped"