From 2f1c4cfba8ab3f56e3c7c06a76d47ae4e50dee01 Mon Sep 17 00:00:00 2001 From: Aanya Date: Mon, 30 Mar 2026 15:21:11 +0530 Subject: [PATCH] Implement error handling for send_mail in notifications This PR improves the robustness of the send_notification function by adding error handling around the email sending logic. Changes: - Wrapped send_mail in a try-except block - Added logging for failures This ensures that notification creation is not interrupted if email sending fails, improving reliability and consistency with existing patterns in the codebase. --- web/notifications.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/web/notifications.py b/web/notifications.py index b36ba2972..421ea463b 100644 --- a/web/notifications.py +++ b/web/notifications.py @@ -28,13 +28,16 @@ def send_notification(user, notification_data): "emails/notification.html", {"user": user, "notification": notification}, ) - send_mail( - subject, - "", - settings.DEFAULT_FROM_EMAIL, - [user.email], - html_message=html_message, - ) + try: + send_mail( + subject, + "", + settings.DEFAULT_FROM_EMAIL, + [user.email], + html_message=html_message, + ) + except Exception as e: + logger.error(f"Failed to send notification email to {user.email}: {str(e)}") return notification