From d06d933c95836136991a0f5f0ba5b067d584327e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 27 Jun 2020 16:54:25 +0900 Subject: [PATCH] Convert InvalidKeyError exception to NotFound This fixes the execption in lms when accessing a blank course via the front-end-learning MFE. --- openedx/core/djangoapps/courseware_api/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/courseware_api/views.py b/openedx/core/djangoapps/courseware_api/views.py index b81a637323..fd453f18c6 100644 --- a/openedx/core/djangoapps/courseware_api/views.py +++ b/openedx/core/djangoapps/courseware_api/views.py @@ -11,7 +11,9 @@ from django.conf import settings from django.urls import reverse from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser +from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey +from rest_framework.exceptions import NotFound from rest_framework.generics import RetrieveAPIView from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response @@ -332,7 +334,10 @@ class SequenceMetadata(DeveloperErrorViewMixin, APIView): """ Return response to a GET request. """ - usage_key = UsageKey.from_string(usage_key_string) + try: + usage_key = UsageKey.from_string(usage_key_string) + except InvalidKeyError: + raise NotFound("Invalid usage key: '{}'.".format(usage_key_string)) sequence, _ = get_module_by_usage_id( self.request,