stages/email: improve error handling

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-04 18:30:23 +02:00
parent 0d370ef0a9
commit 83cfb5f8c2
1 changed files with 7 additions and 2 deletions

View File

@ -48,7 +48,12 @@ def send_mail(
stage: EmailStage = EmailStage(use_global_settings=True) stage: EmailStage = EmailStage(use_global_settings=True)
else: else:
stage: EmailStage = EmailStage.objects.get(pk=email_stage_pk) stage: EmailStage = EmailStage.objects.get(pk=email_stage_pk)
try:
backend = stage.backend backend = stage.backend
except ValueError as exc:
LOGGER.warning(exc)
self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc))
return
backend.open() backend.open()
# Since django's EmailMessage objects are not JSON serialisable, # Since django's EmailMessage objects are not JSON serialisable,
# we need to rebuild them from a dict # we need to rebuild them from a dict
@ -68,7 +73,7 @@ def send_mail(
messages=["Successfully sent Mail."], messages=["Successfully sent Mail."],
) )
) )
except (SMTPException, ConnectionError, ValueError) as exc: except (SMTPException, ConnectionError) as exc:
LOGGER.debug("Error sending email, retrying...", exc=exc) LOGGER.debug("Error sending email, retrying...", exc=exc)
self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc)) self.set_status(TaskResult(TaskResultStatus.ERROR).with_error(exc))
raise exc raise exc