Skip to content

Commit

Permalink
fix: send email only on defined errors
Browse files Browse the repository at this point in the history
  • Loading branch information
syedsajjadkazmii committed Jan 13, 2025
1 parent 333bad6 commit a371e40
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 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 and exc.response.text
if isinstance(exc, RequestException) and exc.response is not None and getattr(exc.response, "text", '')
else str(exc)
)

Expand All @@ -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}, "
Expand Down

0 comments on commit a371e40

Please sign in to comment.