Skip to content

Commit

Permalink
add checking for file error in rejected licence reply
Browse files Browse the repository at this point in the history
  • Loading branch information
markj0hnst0n committed Dec 16, 2024
1 parent f271820 commit 0475b68
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion mail/icms/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

logger = logging.getLogger(__name__)

class EdifactFileError(Exception):
pass

def process_licence_reply_and_usage_emails():
"""Downloads licenceReply and usageData emails from HMRC mailbox and stores in Mail model."""
Expand Down Expand Up @@ -53,12 +55,19 @@ def process_licence_reply_and_usage_emails():
elif "usageData" in subject:
_save_usage_data_email(mail)
con.dele(msg_id)

elif "Licence rejected by HMRC" in subject:
_check_for_file_errors(mail)
con.dele(msg_id)

else:
raise ValueError(f"Unable to process email with subject: {subject}")

except Exception as e:
con.rset()
raise e




@transaction.atomic()
Expand Down Expand Up @@ -237,3 +246,8 @@ def _save_usage_data_email(usage_email: email.message.EmailMessage) -> None:
# extract_type=ExtractTypeEnum.USAGE_DATA
# )
raise NotImplementedError

def _check_for_file_errors(reply_email: email.message.EmailMessage) -> None:
processor = LicenceReplyProcessor.load_from_mail(reply_email)
if file_error in processor.file_errors:
raise EdifactFileError(f"Unable to process file due to the following errors: {error for file_error in processor.file_errors}")

0 comments on commit 0475b68

Please sign in to comment.