From 199034111ab41d05df37dbc81dbc345d5b06c064 Mon Sep 17 00:00:00 2001 From: Carina Antunes <carina.oliveira.antunes@cern.ch> Date: Fri, 1 Oct 2021 16:09:51 +0200 Subject: [PATCH] [hotfix] Exception handling --- .../email_gateway_failure/processor.py | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/notifications_consumer/processors/email_gateway_failure/processor.py b/notifications_consumer/processors/email_gateway_failure/processor.py index a06a392..a3fb6d7 100644 --- a/notifications_consumer/processors/email_gateway_failure/processor.py +++ b/notifications_consumer/processors/email_gateway_failure/processor.py @@ -4,6 +4,7 @@ from typing import Dict from notifications_consumer.config import Config from notifications_consumer.data_source.data_source import DataSource +from notifications_consumer.exceptions import NotFoundDataSourceError from notifications_consumer.processors.email.utils import create_email, send_emails from notifications_consumer.processors.email_gateway.utils import validate_email_recipient_format from notifications_consumer.processors.processor import Processor @@ -68,14 +69,18 @@ class EmailGatewayFailureProcessor(Processor): recipient_email = message_object["to"] match_format = validate_email_recipient_format(recipient_email) error = "Unknown Error while processing message" + channel_slug = match_format[2] if match_format: try: - channel_slug = match_format[2] channel = self.data_source.get_channel(channel_slug) channel_mail = channel[DataSource.INCOMING_EMAIL] + return self.__send_notification_email(channel_mail, message_object, error, channel_slug) - except Exception as ex: - logging.exception("Error while parsing %s email", recipient_email, exception=ex) + except NotFoundDataSourceError: + error = f"Bad Request: Channel {channel_slug} not found" + logging.info("Channel not found %s", channel_slug) + except Exception: + logging.exception("Error while parsing %s email", recipient_email) sender = message_object.get("sender") if sender: @@ -101,13 +106,6 @@ class EmailGatewayFailureProcessor(Processor): if channel: context["channel"] = channel - email = create_email( - [recipient_email], - subject, - text_template, - html_template, - context, - True - ) + email = create_email([recipient_email], subject, text_template, html_template, context, True) return send_emails([email]) -- GitLab