refactor: Add logging to mobile_api app (#33064)

This commit is contained in:
Moeez Zahid
2023-08-23 16:20:20 +05:00
committed by GitHub
parent 6a346c2126
commit 7ae64a5eb4
2 changed files with 10 additions and 0 deletions

View File

@@ -132,6 +132,7 @@ class CourseGoalsRecordUserActivity(APIView):
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 @@ class CourseGoalsRecordUserActivity(APIView):
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 @@ class CourseGoalsRecordUserActivity(APIView):
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,

View File

@@ -3,6 +3,8 @@ Views for user API
"""
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 .. import errors
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 @@ class UserCourseStatus(views.APIView):
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 @@ class UserCourseStatus(views.APIView):
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)