From 333bad6031f00c977f00cc328cd1e337c862157b Mon Sep 17 00:00:00 2001 From: Syed Sajjad Hussain Shah Date: Thu, 9 Jan 2025 16:35:22 +0500 Subject: [PATCH 1/2] feat: send enrollment/fulfillment failure email for any error --- commerce_coordinator/apps/lms/tasks.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/commerce_coordinator/apps/lms/tasks.py b/commerce_coordinator/apps/lms/tasks.py index 85407a84..599d2787 100644 --- a/commerce_coordinator/apps/lms/tasks.py +++ b/commerce_coordinator/apps/lms/tasks.py @@ -35,7 +35,7 @@ def on_failure(self, exc, task_id, args, kwargs, einfo): error_message = ( json.loads(exc.response.text).get('message', '') - if isinstance(exc, RequestException) and exc.response is not None + if isinstance(exc, RequestException) and exc.response is not None and exc.response.text else str(exc) ) @@ -46,11 +46,7 @@ def on_failure(self, exc, task_id, args, kwargs, einfo): f"order number: {order_number}, and course title: {course_title}" ) - # This error is returned from LMS if the course mode is unsupported - # https://github.com/openedx/edx-platform/blob/master/openedx/core/djangoapps/enrollments/views.py#L870 - course_mode_expired_error = "course mode is expired or otherwise unavailable for course run" - - if course_mode_expired_error in error_message: + if isinstance(exc, RequestException): logger.info( f"Sending unsupported course mode fulfillment error email " f"for the user with user ID: {edx_lms_user_id}, email: {user_email}, " From a371e4050de5b7c0b0dec29dc7bde5729039dfa0 Mon Sep 17 00:00:00 2001 From: Syed Sajjad Hussain Shah Date: Mon, 13 Jan 2025 17:44:07 +0500 Subject: [PATCH 2/2] fix: send email only on defined errors --- commerce_coordinator/apps/lms/tasks.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/commerce_coordinator/apps/lms/tasks.py b/commerce_coordinator/apps/lms/tasks.py index 599d2787..94bf619d 100644 --- a/commerce_coordinator/apps/lms/tasks.py +++ b/commerce_coordinator/apps/lms/tasks.py @@ -35,7 +35,7 @@ def on_failure(self, exc, task_id, args, kwargs, einfo): error_message = ( json.loads(exc.response.text).get('message', '') - if isinstance(exc, RequestException) and exc.response is not None and exc.response.text + if isinstance(exc, RequestException) and exc.response is not None and getattr(exc.response, "text", '') else str(exc) ) @@ -46,7 +46,14 @@ def on_failure(self, exc, task_id, args, kwargs, einfo): f"order number: {order_number}, and course title: {course_title}" ) - if isinstance(exc, RequestException): + # These errors can be either returned from LMS enrollment API or can be due to connection timeouts. + fulfillment_error_messages = [ + "course mode is expired or otherwise unavailable for course run", + "Read timed out.", + "Service Unavailable" + ] + + if any(err_msg in error_message for err_msg in fulfillment_error_messages): logger.info( f"Sending unsupported course mode fulfillment error email " f"for the user with user ID: {edx_lms_user_id}, email: {user_email}, "