Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 16 additions & 3 deletions courses/views/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,22 @@ def partial_update(self, request, *args, **kwargs): # noqa: ARG002
NoEdxApiAuthError,
HTTPError,
RequestsConnectionError,
) as exc:
log.exception(str(exc)) # noqa: TRY401
return Response(data=str(exc), status=status.HTTP_400_BAD_REQUEST)
):
# Log full details for debugging
log.exception(
"Failed to update email subscription for user %s, enrollment %s, receive_emails=%s",
request.user.id,
enrollment.id,
receive_emails,
)

# Return user-friendly error
return Response(
data={
"error": "Unable to update email preferences at this time. Please try again later or contact support."
},
status=status.HTTP_400_BAD_REQUEST,
)
else:
# only designed to update edx_emails_subscription field
# TODO: In the future please add the implementation # noqa: FIX002, TD002, TD003
Expand Down
4 changes: 4 additions & 0 deletions courses/views/v1/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,10 @@ def test_update_user_enrollment_failure(
data={"receive_emails": "on" if receive_emails else ""},
)
assert resp.status_code == status.HTTP_400_BAD_REQUEST
# Update assertion to check for the new generic error message
assert resp.json() == {
"error": "Unable to update email preferences at this time. Please try again later or contact support."
}
patched_email_subscription.assert_called_once_with(user, run_enrollment.run)
patched_log_exception.assert_called_once()

Expand Down