Skip to content

Commit

Permalink
feat: send enrollment/fulfillment failure email for any error
Browse files Browse the repository at this point in the history
  • Loading branch information
syedsajjadkazmii committed Jan 9, 2025
1 parent d333aef commit 2a3b624
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions commerce_coordinator/apps/lms/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand All @@ -46,25 +46,21 @@ 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:
logger.info(
f"Sending unsupported course mode fulfillment error email "
f"for the user with user ID: {edx_lms_user_id}, email: {user_email}, "
f"order number: {order_number}, and course title: {course_title}"
)

canvas_entry_properties = {
'order_number': order_number,
'product_type': 'course', # TODO: Fetch product type from commercetools product object
'product_name': course_title,
'first_name': user_first_name,
}
# Send failure notification email
send_unsupported_mode_fulfillment_error_email(edx_lms_user_id, user_email, canvas_entry_properties)
canvas_entry_properties = {
'order_number': order_number,
'product_type': 'course', # TODO: Fetch product type from commercetools product object
'product_name': course_title,
'first_name': user_first_name,
}

logger.info(
f"Sending unsupported course mode fulfillment error email "
f"for the user with user ID: {edx_lms_user_id}, email: {user_email}, "
f"order number: {order_number}, and course title: {course_title}"
)

# Send failure notification email
send_unsupported_mode_fulfillment_error_email(edx_lms_user_id, user_email, canvas_entry_properties)


@shared_task(
Expand Down

0 comments on commit 2a3b624

Please sign in to comment.