Skip to content

Commit 7ae64a5

Browse files
authored
refactor: Add logging to mobile_api app (openedx#33064)
1 parent 6a346c2 commit 7ae64a5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lms/djangoapps/mobile_api/course_info/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def post(self, request, *args, **kwargs):
132132
course_key = request.data.get('course_key')
133133

134134
if not user_id or not course_key:
135+
log.error('User id and course key are required. %s %s', user_id, course_key)
135136
return Response(
136137
'User id and course key are required',
137138
status=status.HTTP_400_BAD_REQUEST,
@@ -141,6 +142,7 @@ def post(self, request, *args, **kwargs):
141142
user_id = int(user_id)
142143
user = User.objects.get(id=user_id)
143144
except User.DoesNotExist:
145+
log.error('Provided user id does not correspond to an existing user %s', user_id)
144146
return Response(
145147
'Provided user id does not correspond to an existing user',
146148
status=status.HTTP_400_BAD_REQUEST,
@@ -149,6 +151,7 @@ def post(self, request, *args, **kwargs):
149151
try:
150152
course_key = CourseKey.from_string(course_key)
151153
except InvalidKeyError:
154+
log.error('Provided course key is not valid %s', course_key)
152155
return Response(
153156
'Provided course key is not valid',
154157
status=status.HTTP_400_BAD_REQUEST,

lms/djangoapps/mobile_api/users/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44

55

6+
import logging
7+
68
from completion.exceptions import UnavailableCompletionData
79
from completion.utilities import get_key_to_last_completed_block
810
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
@@ -37,6 +39,8 @@
3739
from ..decorators import mobile_course_access, mobile_view
3840
from .serializers import CourseEnrollmentSerializer, CourseEnrollmentSerializerv05, UserSerializer
3941

42+
log = logging.getLogger(__name__)
43+
4044

4145
@mobile_view(is_user=True)
4246
class UserDetail(generics.RetrieveAPIView):
@@ -178,6 +182,7 @@ def _update_last_visited_module_id(self, request, course, module_key, modificati
178182
try:
179183
descriptor = modulestore().get_item(module_key)
180184
except ItemNotFoundError:
185+
log.error(f"{errors.ERROR_INVALID_MODULE_ID} %s", module_key)
181186
return Response(errors.ERROR_INVALID_MODULE_ID, status=400)
182187
block = get_block_for_descriptor(
183188
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
228233
if modification_date_string:
229234
modification_date = dateparse.parse_datetime(modification_date_string)
230235
if not modification_date or not modification_date.tzinfo:
236+
log.error(f"{errors.ERROR_INVALID_MODIFICATION_DATE} %s", modification_date_string)
231237
return Response(errors.ERROR_INVALID_MODIFICATION_DATE, status=400)
232238

233239
if module_id:
234240
try:
235241
module_key = UsageKey.from_string(module_id)
236242
except InvalidKeyError:
243+
log.error(f"{errors.ERROR_INVALID_MODULE_ID} %s", module_id)
237244
return Response(errors.ERROR_INVALID_MODULE_ID, status=400)
238245

239246
return self._update_last_visited_module_id(request, course, module_key, modification_date)

0 commit comments

Comments
 (0)