diff --git a/lms/djangoapps/mobile_api/course_info/views.py b/lms/djangoapps/mobile_api/course_info/views.py index cb474a5fd754..5c29dc1b5d58 100644 --- a/lms/djangoapps/mobile_api/course_info/views.py +++ b/lms/djangoapps/mobile_api/course_info/views.py @@ -132,6 +132,7 @@ def post(self, request, *args, **kwargs): course_key = request.data.get('course_key') if not user_id or not course_key: + log.error('User id and course key are required. %s %s', user_id, course_key) return Response( 'User id and course key are required', status=status.HTTP_400_BAD_REQUEST, @@ -141,6 +142,7 @@ def post(self, request, *args, **kwargs): user_id = int(user_id) user = User.objects.get(id=user_id) except User.DoesNotExist: + log.error('Provided user id does not correspond to an existing user %s', user_id) return Response( 'Provided user id does not correspond to an existing user', status=status.HTTP_400_BAD_REQUEST, @@ -149,6 +151,7 @@ def post(self, request, *args, **kwargs): try: course_key = CourseKey.from_string(course_key) except InvalidKeyError: + log.error('Provided course key is not valid %s', course_key) return Response( 'Provided course key is not valid', status=status.HTTP_400_BAD_REQUEST, diff --git a/lms/djangoapps/mobile_api/users/views.py b/lms/djangoapps/mobile_api/users/views.py index eca113a88465..45a3e61bb5c5 100644 --- a/lms/djangoapps/mobile_api/users/views.py +++ b/lms/djangoapps/mobile_api/users/views.py @@ -3,6 +3,8 @@ """ +import logging + from completion.exceptions import UnavailableCompletionData from completion.utilities import get_key_to_last_completed_block from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user @@ -37,6 +39,8 @@ from ..decorators import mobile_course_access, mobile_view from .serializers import CourseEnrollmentSerializer, CourseEnrollmentSerializerv05, UserSerializer +log = logging.getLogger(__name__) + @mobile_view(is_user=True) class UserDetail(generics.RetrieveAPIView): @@ -178,6 +182,7 @@ def _update_last_visited_module_id(self, request, course, module_key, modificati try: descriptor = modulestore().get_item(module_key) except ItemNotFoundError: + log.error(f"{errors.ERROR_INVALID_MODULE_ID} %s", module_key) return Response(errors.ERROR_INVALID_MODULE_ID, status=400) block = get_block_for_descriptor( request.user, request, descriptor, field_data_cache, course.id, course=course @@ -228,12 +233,14 @@ def patch(self, request, course, *args, **kwargs): # lint-amnesty, pylint: disa if modification_date_string: modification_date = dateparse.parse_datetime(modification_date_string) if not modification_date or not modification_date.tzinfo: + log.error(f"{errors.ERROR_INVALID_MODIFICATION_DATE} %s", modification_date_string) return Response(errors.ERROR_INVALID_MODIFICATION_DATE, status=400) if module_id: try: module_key = UsageKey.from_string(module_id) except InvalidKeyError: + log.error(f"{errors.ERROR_INVALID_MODULE_ID} %s", module_id) return Response(errors.ERROR_INVALID_MODULE_ID, status=400) return self._update_last_visited_module_id(request, course, module_key, modification_date)