Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: send enrollment/fulfillment failure email for any error #319

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 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 getattr(exc.response, "text", '')
else str(exc)
)

Expand All @@ -46,11 +46,14 @@ 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"
# 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 course_mode_expired_error in error_message:
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}, "
Expand Down
Loading