Files
edx-platform/lms/djangoapps/courseware/exceptions.py
Kyle McCormick 54d5f7f394 Course Blocks API: Fix handling of incorrectly-cased course keys (#25911)
Commit 7f59688 attempted to solve this using
`CourseOverview.course_exists`, but that check is case-
insensitive. This commit instead does a small refactor
to `lms.djangoapps.courseware.get_course` so that we can
handle a failed course lookup without broadly catching
a `ValueError`.
2020-12-18 11:26:29 -05:00

44 lines
1.2 KiB
Python

"""
Exception classes used in lms/courseware.
"""
class Redirect(Exception):
"""
Exception class that requires redirecting to a URL.
"""
def __init__(self, url):
super(Redirect, self).__init__()
self.url = url
class CourseAccessRedirect(Redirect):
"""
Redirect raised when user does not have access to a course.
Arguments:
url (string): The redirect url.
access_error (AccessErro): The AccessError that caused the redirect.
The AccessError contains messages for developers and users explaining why
the user was denied access. These strings can then be exposed to the user.
"""
def __init__(self, url, access_error=None):
super(CourseAccessRedirect, self).__init__(url)
self.access_error = access_error
class CourseRunNotFound(ValueError):
"""
Indicate that a supplied course run key does not map to a course run in the system.
"""
def __init__(self, course_key):
"""
Initialize CourseRunNotFound exception.
Arguments:
course_key (CourseKey|str):
course run key or stringified version thereof.
"""
super().__init__(f"Course run not found: {course_key}")