From b2e963003fe86402d54c3e68af680f19dc8ad49f Mon Sep 17 00:00:00 2001 From: Khai Tran Date: Mon, 3 Jun 2024 22:49:47 +0700 Subject: [PATCH] chore: Handle aws ssl error --- src/maily/aws/ses.py | 4 ++-- src/maily/message.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/maily/aws/ses.py b/src/maily/aws/ses.py index 699ac74..f032646 100644 --- a/src/maily/aws/ses.py +++ b/src/maily/aws/ses.py @@ -3,7 +3,7 @@ from maily.aws import AWS from maily.logger import logger from email.mime.text import MIMEText -from botocore.exceptions import ClientError, ConnectionClosedError +from botocore.exceptions import ClientError, ConnectionClosedError, SSLError from email.mime.multipart import MIMEMultipart from maily.locker_api import store_reply_record from email.mime.application import MIMEApplication @@ -105,7 +105,7 @@ def ses_send_raw_email(self, from_address, to_address, subject, message_body, at # logger.error( # f'from_address: {from_address}\nto_address: {to_address}\ndata: {msg_with_attachments.as_string()}') return False - except ConnectionClosedError: + except (ConnectionClosedError, SSLError): return None return True diff --git a/src/maily/message.py b/src/maily/message.py index fb4ca9e..3bb46bd 100644 --- a/src/maily/message.py +++ b/src/maily/message.py @@ -9,7 +9,7 @@ from urllib.request import urlopen from maily.aws.s3 import s3_client from maily.aws.ses import ses_client -from botocore.exceptions import ClientError +from botocore.exceptions import ClientError, ConnectionClosedError, SSLError from email import message_from_bytes, policy from django.utils.encoding import smart_bytes from maily.exceptions import InReplyToNotFound @@ -234,7 +234,7 @@ def get_text_html_attachments(self): # we are returning a 500 so that SNS can retry the email processing # return self.response(503, "Cannot fetch the message content from S3") return self.response(504, "Fetch message from S3 error - boto3.ClientError") - except botocore.exceptions.ConnectionClosedError: + except (ConnectionClosedError, SSLError): return self.response(504, "Fetch message from S3 error - boto3.ConnectionClosedError") else: message_content = self.sns_message_content