Handle email errors in a better manner
This commit is contained in:
parent
793b6f543c
commit
93cd7de0e0
3 changed files with 19 additions and 3 deletions
|
@ -20,6 +20,7 @@ from functools import wraps
|
|||
from config import getFrontendVisibleConfig
|
||||
from external_libraries import get_external_javascript, get_external_css
|
||||
from endpoints.notificationhelper import spawn_notification
|
||||
from util.useremails import CannotSendEmailException
|
||||
|
||||
import features
|
||||
|
||||
|
@ -129,6 +130,11 @@ def handle_dme(ex):
|
|||
logger.exception(ex)
|
||||
return make_response(json.dumps({'message': ex.message}), 400)
|
||||
|
||||
@app.errorhandler(CannotSendEmailException)
|
||||
def handle_emailexception(ex):
|
||||
logger.exception(ex)
|
||||
message = 'Could not send email. Please contact an administrator and report this problem.'
|
||||
return make_response(json.dumps({'message': message}), 400)
|
||||
|
||||
def random_string():
|
||||
random = SystemRandom()
|
||||
|
|
|
@ -2644,9 +2644,9 @@ quayApp.directive('userSetup', function () {
|
|||
$scope.errorMessage = '';
|
||||
$scope.sent = true;
|
||||
$scope.sendingRecovery = false;
|
||||
}, function(result) {
|
||||
}, function(resp) {
|
||||
$scope.invalidRecovery = true;
|
||||
$scope.errorMessage = result.data;
|
||||
$scope.errorMessage = ApiService.getErrorMessage(resp, 'Cannot send recovery email');
|
||||
$scope.sent = false;
|
||||
$scope.sendingRecovery = false;
|
||||
});
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import logging
|
||||
import traceback
|
||||
|
||||
from flask.ext.mail import Message
|
||||
|
||||
from app import mail, app, get_app_url
|
||||
|
@ -5,8 +8,12 @@ from data import model
|
|||
from util.gravatar import compute_hash
|
||||
from util.jinjautil import get_template_env
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
template_env = get_template_env("emails")
|
||||
|
||||
class CannotSendEmailException(Exception):
|
||||
pass
|
||||
|
||||
def send_email(recipient, subject, template_file, parameters):
|
||||
app_title = app.config['REGISTRY_TITLE_SHORT']
|
||||
app_url = get_app_url()
|
||||
|
@ -30,8 +37,11 @@ def send_email(recipient, subject, template_file, parameters):
|
|||
|
||||
msg = Message('[%s] %s' % (app_title, subject), recipients=[recipient])
|
||||
msg.html = rendered_html
|
||||
mail.send(msg)
|
||||
|
||||
try:
|
||||
mail.send(msg)
|
||||
except Exception as ex:
|
||||
raise CannotSendEmailException(ex.message)
|
||||
|
||||
def send_password_changed(username, email):
|
||||
send_email(email, 'Account password changed', 'passwordchanged', {
|
||||
|
|
Reference in a new issue