Skip to content

Commit

Permalink
Log top-level errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TheByronHimes committed Jan 16, 2024
1 parent 937e72e commit 76e7e6a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ns/core/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
#
"""Contains the concrete implementation of a NotifierPort"""
import logging
from email.message import EmailMessage
from string import Template

Expand All @@ -24,6 +25,8 @@
from ns.ports.inbound.notifier import NotifierPort
from ns.ports.outbound.smtp_client import SmtpClientPort

log = logging.getLogger(__name__)


class NotifierConfig(BaseSettings):
"""Config details for the notifier"""
Expand All @@ -48,8 +51,12 @@ def __init__(self, *, config: NotifierConfig, smtp_client: SmtpClientPort):
async def send_notification(self, *, notification: event_schemas.Notification):
"""Sends notifications based on the channel info provided (e.g. email addresses)"""
if len(notification.recipient_email) > 0:
message = self._construct_email(notification=notification)
self._smtp_client.send_email_message(message)
try:
message = self._construct_email(notification=notification)
self._smtp_client.send_email_message(message)
except (self.BadTemplateFormat, SmtpClientPort.GeneralSmtpException) as err:
log.fatal(msg=str(err))
raise

def _construct_email(
self, *, notification: event_schemas.Notification
Expand Down

0 comments on commit 76e7e6a

Please sign in to comment.