Skip to content

Commit

Permalink
refactor: Add logging to mobile_api app (openedx#33064)
Browse files Browse the repository at this point in the history
  • Loading branch information
moeez96 authored Aug 23, 2023
1 parent 6a346c2 commit 7ae64a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lms/djangoapps/mobile_api/course_info/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions lms/djangoapps/mobile_api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7ae64a5

Please sign in to comment.