Skip to content

Commit

Permalink
fix: chain re-raising exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpalmerio committed Oct 30, 2023
1 parent fa4e655 commit 70e5658
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions openedx/core/djangoapps/course_roles/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ def get_all_user_permissions_for_a_course(user_id, course_id):
raise ValueError(_('user_id and course_id must not be None'))
try:
user = User.objects.get(pk=user_id)
except User.DoesNotExist:
raise ValueError(_('user does not exist'))
except User.DoesNotExist as exc:
raise ValueError(_('user does not exist')) from exc
try:
course = modulestore().get_course(course_id)
except AssertionError:
raise ValueError(_('course_id is not valid'))
except AssertionError as exc:
raise ValueError(_('course_id is not valid')) from exc
if not course:
raise ValueError(_('course does not exist'))
course_permissions = set(CourseRolesUserRole.objects.filter(
Expand Down
8 changes: 4 additions & 4 deletions openedx/core/djangoapps/course_roles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def get(self, request):
raise ParseError('Required course_id parameter is missing')
try:
course_key = CourseKey.from_string(course_id)
except InvalidKeyError:
raise ParseError('Invalid course_id parameter')
except InvalidKeyError as exc:
raise ParseError('Invalid course_id parameter') from exc
try:
permissions = {
'permissions': get_all_user_permissions_for_a_course(user_id, course_key),
}
except ValueError as e:
raise NotFound(str(e))
except ValueError as exc:
raise NotFound(str(exc)) from exc
return Response(permissions)

0 comments on commit 70e5658

Please sign in to comment.