Skip to content

Commit

Permalink
Simplify adapter as service already handles exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobessa committed Dec 4, 2024
1 parent 43522d2 commit 62a51a5
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions vintasend_django/services/notification_adapters/django_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from vintasend.services.notification_adapters.base import BaseNotificationAdapter
from vintasend.services.notification_template_renderers.base_templated_email_renderer import BaseTemplatedEmailRenderer
from vintasend.app_settings import NotificationSettings
from vintasend.constants import NotificationStatus


if TYPE_CHECKING:
Expand Down Expand Up @@ -49,11 +50,7 @@ def send(
context_with_base_url: "NotificationContextDict" = context.copy()
context_with_base_url["base_url"] = f"{notification_settings.NOTIFICATION_DEFAULT_BASE_URL_PROTOCOL}://{notification_settings.NOTIFICATION_DEFAULT_BASE_URL_DOMAIN}"

try:
template = self.template_renderer.render(notification, context_with_base_url)
except NotificationTemplateRenderingError as e:
self.backend.mark_pending_as_failed(notification.id)
raise NotificationTemplateRenderingError() from e
template = self.template_renderer.render(notification, context_with_base_url)

email = EmailMessage(
subject=template.subject.strip(),
Expand All @@ -65,10 +62,4 @@ def send(
)
email.content_subtype = "html"

try:
email.send()
except Exception as e: # noqa: BLE001
self.backend.mark_pending_as_failed(notification.id)
raise NotificationSendError() from e

self.backend.mark_pending_as_sent(notification.id)
email.send()

0 comments on commit 62a51a5

Please sign in to comment.